x++ code to get Vendor Email Address based on Purpose in Dynamics 365 for Operations

PHOTO EMBED

Sun Sep 01 2024 09:51:21 GMT+0000 (Coordinated Universal Time)

Saved by @Manjunath

public static  Email   getVendorEmailAddress()
    {
     
        VendTable  vendTable;
        DirPartyLocation dirPartyLocation;
        LogisticsElectronicAddress elecAddress;
        LogisticsElectronicAddressRole elecAddressRole;
        LogisticsLocationRole locRole;
        Str vendNum;
     
       vendNum='205181';//Vendor Number
       

        select firstonly  DirPartyLocation
                    where dirPartyLocation.party ==  VendTable::find(vendNum).Party//Vendor Number
            join   elecAddress
                    where elecAddress.Location == dirPartyLocation.Location
                        && elecAddress.Type == LogisticsElectronicAddressMethodType::Email
            && elecAddress.IsPrimary ==  NoYes::Yes
        exists join elecAddressRole
                    where elecAddressRole.ElectronicAddress == elecAddress.RecId
            join locRole
                    where locRole.RecId == elecAddressRole.LocationRole
            && locRole.Type == LogisticsLocationRoleType::Other;//Purpose,we can change here
     
        return elecAddress.Locator;
    }
content_copyCOPY

find contact details of customer or vendor based on purpose

https://vijayaxtechnical.blogspot.com/2018/02/x-code-to-get-vendor-email-address.html