Working with customer/vendor contact information

Fetch customer contact information (email/phone)
    CustTable                   custTable   = CustTable::find('2001');
    LogisticsElectronicAddress  electronicAddress;
    DirPartyLocation            dirPartyLoc;
    while select RecId from dirPartyLoc
        where dirPartyLoc.Party == custTable.Party
        join IsPrimary, Locator, Type FROM electronicAddress
            where (electronicAddress.Type       == LogisticsElectronicAddressMethodType::Email
                    || electronicAddress.Type   == LogisticsElectronicAddressMethodType::Phone)
                &&electronicAddress.Location== dirPartyLoc.Location
    {
    }
Update/create new contact info record, where first parameter is vendor/customer Party RecId
protected void updateElectronicAddress(RefRecId _dirPartyRecId, LogisticsElectronicAddressMethodType _type, LogisticsElectronicAddressLocator _locator)
{
    container                   defaultRole = map2Con(LogisticsLocationEntity::getDefaultLocationRoleFromEntity(tableNum(DirPartyTable)));
    LogisticsElectronicAddress  electronicAddress;
    
    ttsBegin;
    electronicAddress.Type     = _type;
    electronicAddress.Locator  = _locator;

    electronicAddress.Location = DirPartyLocation::findOrCreate(_dirPartyRecId, 0).Location;

    // find or create the new logisticsElectronicAddress
    electronicAddress = LogisticsElectronicAddress::findOrCreate(electronicAddress);

    // re-select record required for the case if record already exists
    electronicAddress = LogisticsElectronicAddress::findRecId(electronicAddress.RecId, true);

    // Set primary. Setting primary on creation does not work
    electronicAddress.IsPrimary = NoYes::Yes;

    electronicAddress.update();

    // At this point, we need to mark the "purpose" of the number.  Default role "Business"
    LogisticsEntityLocationRoleMap::createEntityLocationRoles(tableNum(LogisticsElectronicAddressRole), electronicAddress.RecId, conPeek(defaultRole, 1), true);
    
    ttsCommit;
}


 

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