web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

X++ code to check whether the contact type of concerned role is present on a customer in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post we will see the code that helps us to know whether the required contact type of concerned role is present on a given customer or not. For demo purpose, chosen customer by name "TestCustomer" to display the contact info where type is Email, role is business and name is abc@gmail.com.

Customer info

Note: CG_CheckContactTypeExists is a runnable class

class CG_CheckContactTypeExists
{       
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        DirPartyLocation                dirPartyLocation;
        LogisticsLocation               location;
        LogisticsElectronicAddress      address;
        LogisticsElectronicAddressRole  addressLocationRole;
        LogisticsLocationRole           locationRole;
        DirPartyTable                   dirPartyTable;
        CustTable                       custTable;
 
        select AccountNum from custTable
            where custTable.AccountNum == "10049"
            join RecId from dirPartyTable
                where dirPartyTable.RecId == custTable.Party;
 
        select Location, RecId from dirPartyLocation
            where dirPartyLocation.Party == dirPartyTable.RecId
            join RecId from location
                where location.RecId == dirPartyLocation.Location
                join address
                where ((address.Type == LogisticsElectronicAddressMethodType::Email)
                    && (address.Location == location.RecId))
                    exists join RecId from addressLocationRole
                        where (addressLocationRole.ElectronicAddress == address.RecId)
                            exists join RecId from locationRole
                                where ((addressLocationRole.LocationRole == locationRole.RecId)
                                    && (locationRole.IsContactInfo == NoYes::Yes)
                                    && (locationRole.Name == "Business"));
 
        if (dirPartyLocation.RecId)
        {
            Info(strFmt("Contact of type Email with %1 exists for customer %2", address.Locator, custTable.AccountNum));
        }
    }
 
}

Output

Regards,

Chaitanya Golla

Comments

*This post is locked for comments