Hi Everyone,
I have been working on a requirement to fetch the email and phone number associated with a specific site ID. To test my joins and logic, I created a runnable class.
Problem Statement:
While I am able to retrieve the correct phone number associated with the site ID, I am unable to fetch the email. Upon reviewing the data in SQL, I verified that the email record does exist. However, I noticed discrepancies in the RecId
and Location
values between the results in my job and those in the database. for Email and don't know the relationship beside this which i can add if needed .
Could you help me understand why the email is not being fetched and guide me on the necessary corrections to retrieve both the phone number and email successfully in D365 F&O?
internal final class HappyJob
{
public static void testContactLogic(str _siteId)
{
InventSite inventSite = InventSite::find(_siteId);
InventLocation inventLocation;
LogisticsElectronicAddress electronicAddressPhone, electronicAddressEmail;
inventLocation = InventLocation::find(inventSite.SiteId);
if (inventLocation)
{
electronicAddressPhone = HappyJob::getValidElectronicAddress(inventLocation, LogisticsElectronicAddressMethodType::Phone);
if (electronicAddressPhone)
{
info(strFmt("Site ID: %1", inventSite.SiteId));
info(strFmt("Primary contact phone: %1", electronicAddressPhone.Locator));
}
electronicAddressEmail = HappyJob::getValidElectronicAddress(inventLocation, LogisticsElectronicAddressMethodType::Email);
if (electronicAddressEmail)
{
info(strFmt("Primary contact email: %1", electronicAddressEmail.Locator));
}
}
}
public static LogisticsElectronicAddress getValidElectronicAddress(InventLocation _inventLocation, LogisticsElectronicAddressMethodType _type)
{
LogisticsLocation logisticsLocation;
InventLocationLogisticsLocation inventLocationLogisticsLocation;
LogisticsPostalAddress logisticsPostalAddress;
LogisticsElectronicAddress electronicAddress;
utcdatetime today = systemDateGet();
select firstOnly inventLocationLogisticsLocation
where inventLocationLogisticsLocation.InventLocation == _inventLocation.RecId
join logisticsLocation
where logisticsLocation.RecId == inventLocationLogisticsLocation.Location;
if (logisticsLocation)
{
select firstOnly logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.ValidFrom <= today
&& logisticsPostalAddress.ValidTo >= today;
if (logisticsPostalAddress)
{
select firstOnly electronicAddress
where electronicAddress.RecId == logisticsPostalAddress.RecId
&& electronicAddress.Type == _type;
if (electronicAddress)
{
return LogisticsElectronicAddress::findByElectronicAddressId(electronicAddress.ElectronicAddressId, true);
}
}
}
return null;
}
public static void main(Args _args)
{
HappyJob::testContactLogic("AHD");
}
}
Thanks,