Creating an Encrypted Field in Dynamics 365 Finance and Operations - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Friday, June 14, 2024

Creating an Encrypted Field in Dynamics 365 Finance and Operations

 Creating an Encrypted Field in Dynamics 365 Finance and Operations
x





Today’s quick and easy X++ post will guide you through the process of creating an encrypted field in Dynamics 365 Finance and Operations (D365 F&O). Encrypting sensitive information helps secure it from unauthorized access by encrypting the data using an encryption key, ensuring data safety even if it is accessed inappropriately.

Overview of Encrypted Fields

Encrypted fields, such as the SMTP password in the Email parameters form, are not stored as plain text in the database. Instead, they are encrypted using a key, and the encrypted value is saved. It’s important to note that each environment has a different encryption key. Therefore, when you refresh a sandbox or development environment with data from another environment, encrypted field values are lost because they can’t be decrypted with a different key.

Steps to Create an Encrypted Field

Step 1: Create the Field in a Table

First, you need to add a new field to the relevant table. In this example, we’ll add a field to the

CustParameters
table.

  1. Extend the Table:
    • Extend the
      CustParameters
      table in your model.
    • Go to the Extended Data Types (EDTs) in the Application Object Tree (AOT).
    • Drag and drop the
      EncryptedField
      EDT into the
      CustParameters
      table extension.
    • Name the new field appropriately (e.g.,
      AASEncryptedField
      ).

Step 2: Create a div Extension

Next, create a div extension for the

CustParameters
table to handle the encryption and decryption of the field content.

  1. Add an Edit Method:
    • Create an extension class for the
      CustParameters
      table.
    • Implement an edit method that calls
      Global::editEncryptedField
      .
xpp

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

This method is a regular edit method that uses the

editEncryptedField
method of the
Global
class, which in turn calls the
EncryptForPurpose
and
DecryptForPurpose
kernel methods of the
Appl
class.

Step 3: Add the Field to a Form

Finally, add the field to a form and configure its properties.

  1. Add the Field:

    • Add a string field to the form.
    • Set the
      Data Source
      property of the field to the
      CustParameters
      table.
    • Set the
      Data Method
      property to the
      CustParameters_aristeinfo_Extension.AASEncryptedNameEdit
      method.
    • If the field’s base data type is not a string, add the correct type of new field.
  2. Set Password Style:

    • Set the form field’s
      Password style
      property to
      Yes
      . This ensures that the field content is displayed as encrypted text (e.g., masked with asterisks).

Step 4: Synchronize and Compile

  1. Synchronize the Database:
    • Ensure all changes are synchronized with the database.
  2. Compile the div:
    • Compile the div to make sure there are no errors.

Step 5: Verify in UI and SQL Server

  1. Check in the UI:

    • Open the form in D365 F&O and verify that the field appears encrypted.
  2. Check in SQL Server:

    • Query the table in SQL Server Management Studio (SSMS) to confirm that the field value is stored as encrypted data.
sql

SELECT AASEncryptedField FROM CustParameters

You should see an encrypted value stored in the database, ensuring that the data is secure.

Conclusion

By following these steps, you can create an encrypted field in D365 F&O, adding an extra layer of security to your customizations. Always look at standard application implementations for guidance as they often provide the best approach.

No comments:

Post a Comment