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.
- 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.