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

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;
    }

Comments

Popular posts from this blog

x++ code to add hyperlink to a field in D365FO

x++ code to get Customer Address based on purpose in ax 2012