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


Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

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

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags