D365FO – Get Customer name and Vendor name in X++

In Dynamics AX and Dynamics 365 Finance and Operations (D365FO), retrieving names associated with customer and vendor accounts is a common task,
D365FO – Get Customer name and Vendor name in X++

Introduction

In Dynamics AX and Dynamics 365 Finance and Operations (D365FO), retrieving names associated with customer and vendor accounts is a common task, especially when generating reports or displaying information in user interfaces. The DirPartyTable class provides methods to easily obtain these names based on the party ID.

The following code snippet demonstrates how to retrieve and display the names of a customer and a vendor using their respective party IDs. It leverages the DirPartyTable class to fetch names from the directory party table, ensuring that the correct and current names are obtained.

X++ Code

...

        Str customerName;

        Str vendorName; 

       // Retrieve Customer Name

        customerName = DirPartyTable::getName(CustTable::find('CUST001').Party); 

      // Retrieve Vendor Name

        vendorName = DirPartyTable::getName(VendTable::find('VEND001').Party); 

      // Display the retrieved names

      info(strFmt('Customer Name: %1', customerName));

      info(strFmt('Vendor Name: %1', vendorName));

...

Explanation

Str customerName;: Declares a string variable customerName that will store the name of the customer.

Str vendorName;: Declares a string variable vendorName that will store the name of the vendor.

customerName = DirPartyTable::getName(CustTable::find('CUST001').Party);:

  • CustTable::find('CUST001'): Fetches the customer record with account number 'CUST001' from the CustTable.
  • CustTable::find('CUST001').Party: Retrieves the Party ID associated with the customer.
  • DirPartyTable::getName(...): Calls the getName method to obtain the name associated with the retrieved Party ID, and assigns it to customerName.
vendorName = DirPartyTable::getName(VendTable::find('VEND001').Party);:
  • VendTable::find('VEND001'): Fetches the vendor record with account number 'VEND001' from the VendTable.
  • VendTable::find('VEND001').Party: Retrieves the Party ID associated with the vendor.
  • DirPartyTable::getName(...): Calls the getName method to obtain the name associated with the retrieved Party ID, and assigns it to vendorName.

info(strFmt('Customer Name: %1', customerName));: Displays the customer's name using the info method, formatted with strFmt to show the variable value.

info(strFmt('Vendor Name: %1', vendorName));: Displays the vendor's name using the info method, formatted with strFmt to show the variable value.

Use Case

This code can be useful in scenarios where you need to quickly retrieve and display the names of customers and vendors. This can be applied to enhance user interfaces, generate reports, or automate processes where names need to be referenced or compared. By using party IDs, you ensure that the retrieved names are consistent with the data stored in the system.
Read Also :-
Labels : #xpp ,
Getting Info...

Post a Comment