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
- Extend the Table:
- Extend the CustParameterstable in your model.
- Go to the Extended Data Types (EDTs) in the Application Object Tree (AOT).
- Drag and drop the EncryptedFieldEDT into theCustParameterstable extension.
- Name the new field appropriately (e.g., AASEncryptedField).
- Extend the
Step 2: Create a div Extension
Next, create a div extension for the
- Add an Edit Method:
- Create an extension class for the CustParameterstable.
- Implement an edit method that calls Global::editEncryptedField.
- Create an extension class for the
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
Step 3: Add the Field to a Form
Finally, add the field to a form and configure its properties.
Add the Field:
- Add a string field to the form.
- Set the Data Sourceproperty of the field to theCustParameterstable.
- Set the Data Methodproperty to theCustParameters_aristeinfo_Extension.AASEncryptedNameEditmethod.
- If the field’s base data type is not a string, add the correct type of new field.
Set Password Style:
- Set the form field’s Password styleproperty toYes. This ensures that the field content is displayed as encrypted text (e.g., masked with asterisks).
- Set the form field’s
Step 4: Synchronize and Compile
- Synchronize the Database:
- Ensure all changes are synchronized with the database.
- Compile the div:
- Compile the div to make sure there are no errors.
Step 5: Verify in UI and SQL Server
Check in the UI:
- Open the form in D365 F&O and verify that the field appears encrypted.
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