Create or Update a Contact Information for a customer/vendor in X++ [AX 2012 R3]
{
VendTable VendTable = VendTable::find('PL00001');
LogisticsElectronicAddress logisticsElectronicAddress;
container defaultRole = map2Con(LogisticsLocationEntity::getDefaultLocationRoleFromEntity(tableNum(DirPartyTable)));
ttsBegin;
logisticsElectronicAddress.Type = LogisticsElectronicAddressMethodType::Email;
logisticsElectronicAddress.Locator = 'ramesh.balakrishnan@ao.com';
logisticsElectronicAddress.Location = DirPartyLocation::findOrCreate(VendTable.Party, 0).Location;
logisticsElectronicAddress = LogisticsElectronicAddress::findOrCreate(logisticsElectronicAddress);
logisticsElectronicAddress = LogisticsElectronicAddress::findRecId(logisticsElectronicAddress.RecId, true);
logisticsElectronicAddress.Description = "Official Email";
logisticsElectronicAddress.IsPrimary = NoYes::Yes;
logisticsElectronicAddress.update();
LogisticsEntityLocationRoleMap::createEntityLocationRoles(tableNum(LogisticsElectronicAddressRole), logisticsElectronicAddress.RecId, conPeek(defaultRole, 1), true);
info(strFmt("Created/updated phone number [%1] for customer %2.", logisticsElectronicAddress.Locator, VendTable.AccountNum));
ttsCommit;
}