Skip to main content
X++ Development · · 2 min read

Retrieve Vendor Name, Alias, Email, Phone and Speciality

 Retrieve vendor name, alias, email, phone, and speciality details using X++ in D365 Finance and Operations. 

A

Ahmad Hassan

Dynamics 365 F&O Consultant

Share
Retrieve Vendor Name, Alias, Email, Phone and Speciality

This X++ code retrieves vendor 0001 and its related party information from D365 F&O.
It reads the vendor name and alias, then loops through party locations to find the first available email and phone number.
The collected vendor details are displayed together in a single informational message.

X++ Code

VendTable                   vendTable;
    DirPartyTable                dirPartyTable;
    DirPartyLocation             dirPartyLocation;
    LogisticsElectronicAddress   logisticsElectronicAddressEmail;
    LogisticsElectronicAddress   logisticsElectronicAddressPhone;

    str email, phone;

    select firstOnly vendTable
where vendTable.AccountNum == '0001';

    select firstOnly dirPartyTable
where dirPartyTable.RecId == vendTable.Party;   // 🔹 Vendor Name & Alias

    // Loop through locations and capture first email/phone
    while select dirPartyLocation
where dirPartyLocation.Party == vendTable.Party
    {
        if (!email)
        {
            select firstOnly logisticsElectronicAddressEmail
        where logisticsElectronicAddressEmail.Location == dirPartyLocation.Location
&& logisticsElectronicAddressEmail.Type == LogisticsElectronicAddressMethodType::Email;

            email = logisticsElectronicAddressEmail.Locator;
        }

        if (!phone)
        {
            select firstOnly logisticsElectronicAddressPhone
        where logisticsElectronicAddressPhone.Location == dirPartyLocation.Location
&& logisticsElectronicAddressPhone.Type == LogisticsElectronicAddressMethodType::Phone;

            phone = logisticsElectronicAddressPhone.Locator;
        }
    }

    // Single info message after loop
    info(strFmt("Vendor: %1 | Name: %2 | Alias: %3 | Email: %4 | Phone: %5 | Speciality Box %6" ,
vendTable.AccountNum,
dirPartyTable.Name,
dirPartyTable.NameAlias,
email,
phone, vendTable.SpecialityName));

Process Flow

The code first retrieves vendor account 0001 from VendTable and its related DirPartyTable record.

It then loops through the vendor's party locations and retrieves the first available email and phone address.

Finally, the vendor account, name, alias, email, phone, and SpecialityName are displayed in a single information message.

e574136b-87e9-4a8a-a86a-95163ddc96df.png

Figure: Flow of retrieving and displaying vendor contact and party information.

Found this useful?

Share it with your network

A

Written by

Ahmad Hassan

Microsoft Dynamics 365 Finance & Operation, Technical Consultant

More about me

Related Posts

Comments

Leave a comment