Purpose:
Demonstrate how can get the worker email address by purpose.
Application:
Dynamics 365 for Finance and Operations
Business requirement:
Business requirement is to display worker email address with purpose “Purchase order” in a report.
Solution:
We can use the method below to get the worker email address by purpose which is defined in the extension class of HcmWorker table.
Code
[ExtensionOf(tableStr(HcmWorker))]
internal final class ATLAS_HcmWorker_Table_Extension
{
/// <summary>
/// Get email address by purpose Feb 16, 24 MK.
/// </summary>
/// <remarks>
/// Atlas Dynamics Pty Ltd.
/// </remarks>
public Email emailByPurpose(LogisticsLocationRoleName _name)
{
LogisticsElectronicAddressRole logisticsElectronicAddressRole;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsLocationRole logisticsLocationRole;
LogisticsLocation logisticsLocation;
DirPartyLocation dirPartyLocation;
DirPartyTable dirPartyTable;
DirPerson dirPerson;
select firstOnly logisticsElectronicAddress
where logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
join logisticsElectronicAddressRole
where logisticsElectronicAddressRole.ElectronicAddress == logisticsElectronicAddress.RecId
join logisticsLocationRole
where logisticsLocationRole.RecId == logisticsElectronicAddressRole.LocationRole
&& logisticsLocationRole.Name == _name
join logisticsLocation
where logisticsLocation.RecId == logisticsElectronicAddress.Location
join dirPartyLocation
where dirPartyLocation.Location == logisticsLocation.RecId
join dirPartyTable
where dirPartyTable.RecId == dirPartyLocation.Party
join dirPerson
where dirPerson.RecId == dirPartyTable.RecId
&& dirPerson.RecId == this.Person;
return logisticsElectronicAddress.Locator;
}
}
We can then call this method in the following way to initialize temp table buffer.
purchOrderLineTmp.DimOwnerEmail = (hcmWorker.emailByPurpose(#PurchaseOrder)) ? (hcmWorker.emailByPurpose(#PurchaseOrder)) : hcmWorker.email();