In this post I will be sharing a simple code snippet for Microsoft Dynamics AX 2012 in order to grab Contact information such as Phone, Fax, Email or URL etc. which is relevant to an Entity's specific Address. Obviously, this entity can be a Legal entity (Company), Vendor or Customer in AX.
So yes, first it is good to clarify here that we can add Contact information such as Phone, Email, Fax, URL, Telex etc. in one of the following ways.
(1.) The primary contacts for an Entity such as for a Legal entity (i.e., Company) can be added at Organisation administration > Setup > Organisation > Legal entities form > Contact information fast tab directly.
(2.) Alternatively we can add Address specific Contact information for all an Entity's Addresses and it is a common scenario for an entity such as Company, Vendor or Customer to have multiple Addresses.
For example, in order to give Address specific contact information for a Legal Entity (i.e., Company) use Organisation administration > Setup > Organisation > Legal entities form > Addresses fast tab, select the specific Address of company and click Edit button. This will open up Edit address dialog on which you can add Contact information relevant to this particular Address at Contact information fast tab.
Code snippets:
Following code snippet fetches the Contoso Consulting USA's primary Address's Phone as shown.
static void getCompanyPrimaryAddressContactInfoPhone()
{
DirPartyTable dirPartyTable;
DirPartyLocation dirPartyLocation;
LogisticsLocation logisticsLocation;
LogisticsContactInfoView logisticsContactInfoView;
CompanyInfo companyInfo;
;
companyInfo = companyInfo::findDataArea("ussi");
dirPartyTable = dirPartyTable::findRec(companyInfo.RecId);
while select dirPartyLocation
where dirPartyLocation.Party == DirPartyTable.RecId
&& dirPartyLocation.IsPrimary == true
{
while select logisticsLocation join
logisticsContactInfoView
logisticsContactInfoView
where logisticsLocation.RecId ==
dirPartyLocation.Location
dirPartyLocation.Location
&&
logisticsContactInfoView.ParentLocation ==
logisticsLocation.RecId
logisticsLocation.RecId
&&
logisticsContactInfoView.Type ==
LogisticsElectronicAddressMethodType::Phone
{
info(strFmt("Company Primary Address, Contact Info
- Phone Number is %1"
,logisticsContactInfoView.Locator));
- Phone Number is %1"
,logisticsContactInfoView.Locator));
}
}
}
}
The clause dirPartyLocation.IsPrimary == true fetches the Company's Primary address's Phone.
Now, following code snippet fetches the Non-primary Address's URL for Customer 'Active Transport Inc.' as shown.
static void getCustomerAddressContactInfoURL()
{
DirPartyTable dirPartyTable;
DirPartyLocation dirPartyLocation;
LogisticsLocation logisticsLocation;
LogisticsContactInfoView logisticsContactInfoView;
CustTable custTable;
;
custTable = custTable::find('US_SI_0002');
dirPartyTable = dirPartyTable::findRec(custTable.Party);
while select dirPartyLocation
where dirPartyLocation.Party == DirPartyTable.RecId
&& dirPartyLocation.IsPrimary == false
{
while select logisticsLocation join
logisticsContactInfoView
logisticsContactInfoView
where logisticsLocation.RecId ==
dirPartyLocation.Location
dirPartyLocation.Location
&& logisticsContactInfoView.ParentLocation ==
logisticsLocation.RecId
&& logisticsContactInfoView.Type ==
LogisticsElectronicAddressMethodType::URL
{
info(strFmt("Customer Non-Primacy Address, Contact
Info - URL is: %1"
,logisticsContactInfoView.Locator));
Info - URL is: %1"
,logisticsContactInfoView.Locator));
}
}
}
Happy DAXing!
-Muhammad Asim Khan Afridi
No comments:
Post a Comment