June 06, 2023

Simplifying Data Retrieval with D365FO X++ Lookup Method

Simplifying Data Retrieval with D365FO X++ Lookup Method

Simplifying Data Retrieval with D365FO X++ Lookup Method

Introduction

Microsoft Dynamics 365 for Finance and Operations (D365FO) is a powerful ERP system that offers robust customization capabilities. One such customization option is the ability to write X++ code for lookup methods. These methods can greatly simplify data retrieval and enhance the user experience within the application. In this blog post, we will explore the lookup method in D365FO X++ code and provide a sample code snippet to demonstrate its usage.

Understanding the Lookup Method

The lookup method in D365FO X++ code allows developers to retrieve data from related tables or data sources based on specified criteria. It enables users to select a value from a predefined set of options, providing a seamless way to populate fields with accurate and relevant information. The lookup method essentially acts as a search functionality within the application, making it easier for users to find and select the desired data.

Sample Code

    
public static void lookupDemo(FormStringControl _control)
{
    SysTableLookup        sysTableLookup;
    QueryBuildDataSource  queryBuildDataSource;
    QueryBuildRange       queryBuildRange;

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), _control);
    queryBuildDataSource = sysTableLookup.addDataSource(tablenum(CustTable));

    // Adding a range to filter the lookup results
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, AccountNum));
    queryBuildRange.value("1001");  // Setting the filter value

    sysTableLookup.performFormLookup();  // Opening the lookup form
}
    
  

Explanation

In the above code, we start by creating a new instance of the SysTableLookup class, passing the target table and the control where the lookup will be displayed as parameters. In this case, we use the CustTable table and the _control argument, which represents the form string control.

Next, we add a data source to the lookup using the addDataSource() method. Here, we specify the table we want to retrieve data from (in this case, CustTable).

To filter the lookup results, we add a range using the addRange() method on the queryBuildDataSource. In this example, we filter the results based on the AccountNum field and set the filter value to "1001".

Finally, we call the performFormLookup() method on the sysTableLookup object, which opens the lookup form for the user to select the desired value.

Conclusion

The lookup method in D365FO X++ code provides a convenient way to retrieve and display data from related tables or data sources. By implementing lookup functionality, developers can enhance the user experience by simplifying data selection and ensuring the accuracy of entered values. The code snippet provided above serves as a starting point for utilizing lookup methods in your D365FO customization projects. Experiment with different tables, filters, and fields to tailor the lookup functionality to meet your specific business requirements.

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

May 19, 2023

Configuring Azure Key Vault Parameters in Dynamics 365 Finance and Operations

Configuring Azure Key Vault Parameters in Dynamics 365 Finance and Operations

Configuring Azure Key Vault Parameters in Dynamics 365 Finance and Operations

Introduction:

In this blog post, I will guide you through the process of configuring Azure Key Vault parameters in Dynamics 365 Finance and Operations (referred to as FinOps). This configuration is particularly useful for integration scenarios where sensitive data, such as security keys or certifications, needs to be securely stored. By leveraging Azure Key Vault, we can ensure data encryption and proper management of cryptographic keys and certificates.

Prerequisite Steps:

Before we dive into the configuration, let's go through some prerequisite steps to set the stage for a seamless setup:

  1. Create a Key Vault: Begin by creating a Key Vault in the Azure portal and make a note of the Value URI, which can be found in the overview tab. This Value URI will be needed during the configuration process.
  2. Add Certificates, Secrets, and Keys: Next, add the necessary certificates, secrets, and keys to your Key Vault. These items are essential for secure data storage and retrieval.
  3. App Registration in Azure: Perform an app registration in the Azure portal and store the generated Client ID and Secret Key. This registration will enable secure communication between Dynamics 365 Finance and Operations and the Azure Key Vault.

Configuration Steps:

Now that we have completed the prerequisite steps, let's proceed with the actual configuration of Azure Key Vault parameters in Dynamics 365 Finance and Operations:

  1. Navigate to D365FO: Go to the D365FO application and access the System Administration module.
  2. Open Key Vault Parameters: Within the System Administration module, locate and open the "Key Vault Parameters" form.
  3. Create a New Record: Create a new record in the Key Vault Parameters form, and fill in the required details for the configuration.
  4. Certification Tab: Switch to the Certification tab within the Key Vault Parameters form. Here, you will add the necessary information for each certificate, including Name, Description, Secret, Secret Type, and Version (if applicable). The Secret field should contain a reference to the certificate in the format: vault://<KeyVaultName>/<SecretName>/(Version if any). Set the Secret Type to "Certificate."
  5. Validate Configuration: Click on the Validate button to ensure the settings are properly configured and functioning as expected.

Code Example:

To demonstrate how to access the configured certificate in your code, consider the following sample code snippet:

public class TheAxaptaAccessKeyVault
  {
      public static void main(Args _args)
      {
          KeyVaultCertificateTable kvcTable;
          str value;

          kvcTable = KeyVaultCertificateTable::findByName("TestKeyVault");
          value = KeyVaultCertificateHelper::getManualSecretValue(certTable.RecId);

          info(value); // This will retrieve the value stored in the certificate.
      }
  }

Conclusion:

Congratulations! You have successfully configured Azure Key Vault parameters in Dynamics 365 Finance and Operations. Now you can securely store and access sensitive data, such as certificates and keys, ensuring the highest level of data protection. Implementing this configuration will greatly enhance your integration scenarios and data security practices within the Dynamics 365 environment.

Happy configuring and coding!

#Dynamics365 #Azure #KeyVault #DataSecurity #Integration #Configuration

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta