Thursday, 8 June 2023

Methods used in AOT Query ranges instead of values

Here is a quick tip, how to add methods in an AOT query ranges instead of values. Refer standard query 'CaseListPage_MyOpenCases'















Similary, In front end forms also we can use methods o filter the data. To do this, the method we use should be part of the class SysQueryRangeUtil. If we do not find a suitable method, we can create a custom method and that can be used globally in D365 FO.

In forms, to filter the value, Use the methods within() in the filtration area as shown in the below example.























In the example, we are trying to filter with created date time value less than 10 days from today. This way, we can set the dynamic values in AOT queries or during report generation and batch job creations parameters to use the recurrence with dynamic ranges.

Friday, 2 June 2023

Encrypted field in D365 FO

Creating an encrypted field in Dynamics 365 Finance and Operations is a simple process that can help secure sensitive information in your application. By using an encryption key to encrypt the data, it ensures that the data remains safe even if it is accessed by unauthorized users.

By encrypted field I mean what you see, for example, in the Email parameters form for the SMTP password:





Encrypted fields

These encrypted fields aren’t stored as plain text in the database, instead they’re encrypted (as its name suggests) using a key and that value is saved.

It’s worth mentioning that each environment has a different encryption key, so when you refresh a sandbox or development environment with data from another environment, the values of encrypted fields are lost because they can’t be unencrypted with a different key.

Creating it

You need a new field in a form, you know that the first step is creating it in a table. For this example, I’ll be adding a field to the CustParameters table and form.

So extend the table in your model and go to the EDTs in the AOT and drag and drop the EncryptedField EDT into the CustParameters table extension. Give it the name you want, I’ll name mine TestEncryptedField, and let’s continue.

Next, you need to create a code extension for the CustParameters table. Because encrypted fields are shown on forms as an edit field, we need a method to encrypt and decrypt the content of the field, and that’s what we’ll do here:

[ExtensionOf(tableStr(CustParameters))]
final class CustParameters_Test_Extension
{
    public edit Name TestEncryptedNameEdit(boolean _set, Name _value)
    {
        return Global::editEncryptedField(this, _value, fieldNum(CustParameters, TestEncryptedField), _set);
    }
}

This is a regular edit method, but it’s calling Global’s editEncryptedField method and there it’s calling Appl’s class EncryptForPurpose and DecryptForPurpose kernel methods that do the job.

Defining an EDT as the return type in the method will help us display the right label in the form, so create your EDTs or use one that fits your purpose. I’m using the Name one because this is just a demo!

Finally, we’ll add a string field in the form and set the CustParameters table as its Data Source property, and the CustParameters_Test_Extension.TestEncryptedNameEdit method as its Data Method property. If your field’s base data type is not a string, you need to add the correct type of new field!

Synchronize, compile and let’s take a look at the field in the UI:










You need to set the form field’s property Password style to Yes! Otherwise, it’ll only show plain text. Let me change that…