Select address, phone, email, contact information purposes (roles)

Here is the code to select contac information or addresses purposes (roles):

        CustTable custTable = CustTable::find('12345');

        LogisticsPostalAddress logisticsPostalAddress = custTable.postalAddress();


        DirPartyLocationRole entityLocationRole;

        container                   roleRecIds, roleNames, roleTranslationRecIds;
        LogisticsLocationRole       locationRole;
        LogisticsLocationRoleTranslation locationRoleTransl;
        DirPartyLocation            dirPartyLocation;

        // Addresses
        info(strFmt("Address: %1", logisticsPostalAddress.Address));

        select dirPartyLocation
            where dirPartyLocation.Location == logisticsPostalAddress.Location
            && dirPartyLocation.Party == custTable.Party;

        info('Address purposes:');

        //DirPartyLocation.locationRoles()
        while select LocationRole from entityLocationRole
        where entityLocationRole.PartyLocation == dirPartyLocation.RecId
        join Name from locationRole
            order by locationRole.Name
            where locationRole.RecId == entityLocationRole.LocationRole
                    && locationRole.Type != LogisticsLocationRoleType::OneTime
        outer join Description from locationRoleTransl
            where locationRoleTransl.LocationRole == locationRole.RecId
                    && locationRoleTransl.LanguageId == currentUserLanguage()
        {
            info((locationRoleTransl.Description == '' ? locationRole.Name : locationRoleTransl.Description));
        }

        // Contact information
        LogisticsElectronicAddress electronicAddress = DirParty::primaryElectronicAddress(custTable.Party, LogisticsElectronicAddressMethodType::Phone);

        info(strFmt("Phone: %1", electronicAddress.Locator));

        info('Phone purposes:');

        LogisticsElectronicAddressRole logisticsElectronicAddressRole;
        UserInfo    userInfo;

        //LogisticsElectronicAddress.locationRoles()
        while select LocationRole from logisticsElectronicAddressRole
            join Name from locationRole
            outer join Description from locationRoleTransl
            exists join userInfo
            order by locationRole.Name
            where logisticsElectronicAddressRole.LocationRole == locationRole.RecId &&
                      logisticsElectronicAddressRole.ElectronicAddress == electronicAddress.RecId &&
                      (locationRole.Type != LogisticsLocationRoleType::OneTime) &&
                      locationRoleTransl.LocationRole == locationRole.RecId &&
                      locationRoleTransl.LanguageId == userInfo.Language &&
                      userInfo.Id == curUserId()
        {
            info((locationRoleTransl.Description == '' ? locationRole.Name : locationRoleTransl.Description));
        }


 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags