Fetch customer address using X++ in AX 2012
Hi Technical,
Today, in this post we are going to share a piece of code by which you can fetch customer address using X++ in AX 2012.
Create a AOT job and copy paste the below code to export customer address in excel.
Author:
Chirag Gupta
Microsoft Dynamics 365 AX Technical Consultant at IBM Bangalore
Date:
29-Jan-2020
Happy Learning !!
Today, in this post we are going to share a piece of code by which you can fetch customer address using X++ in AX 2012.
Create a AOT job and copy paste the below code to export customer address in excel.
// Project Name: PKA_WO67963_FetchCustomerVendorAddress
// Created by: Chirag Gupta (ibm.chirag)
// Created date: 18-Dec-19
// Summary: Fetch Customer ID, Name or description, Address, Purpose, Primary
static void PKA_CustomerAddress(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
int row;
CustTable custTable;
DirPartyTable dirPartyTable;
DirPartyLocation dirPartyLocation;
DirPartyLocationRole dirPartyLocationRole;
LogisticsLocation logisticsLocation;
LogisticsLocationRole logisticsLocationRole;
LogisticsPostalAddress logisticsPostalAddress;
str isPrimary;
xlsApplication = SysExcelApplication::construct();
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
row = 1;
xlsWorkSheet.cells().item(row, 1).value("Custome ID");
xlsWorkSheet.cells().item(row, 2).value("Name or description");
xlsWorkSheet.cells().item(row, 3).value("Addresss");
xlsWorkSheet.cells().item(row, 4).value("Purpose");
xlsWorkSheet.cells().item(row, 5).value("Primary");
while select AccountNum from custTable
join Name from dirPartyTable
where dirPartyTable.RecId == custTable.Party
join IsPrimary from dirPartyLocation
where dirPartyLocation.Party == custTable.Party
join dirPartyLocationRole
where dirPartyLocationRole.PartyLocation == dirPartyLocation.RecId
join Type from logisticsLocationRole
where logisticsLocationRole.RecId == dirPartyLocationRole.LocationRole
join logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
{
row++;
xlsWorkSheet.cells().item(row, 1).value(custTable.AccountNum);
xlsWorkSheet.cells().item(row, 2).value(dirPartyTable.Name);
xlsWorkSheet.cells().item(row, 3).value(logisticsPostalAddress.Address);
xlsWorkSheet.cells().item(row, 4).value(enum2str(logisticsLocationRole.Type));
xlsWorkSheet.cells().item(row, 5).value(enum2str(dirPartyLocation.IsPrimary));
}
xlsApplication.visible(true);
}
We hope this article helped you to fetch customer address by using X++. Please comment your valuable feedback for this article...// Created by: Chirag Gupta (ibm.chirag)
// Created date: 18-Dec-19
// Summary: Fetch Customer ID, Name or description, Address, Purpose, Primary
static void PKA_CustomerAddress(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
int row;
CustTable custTable;
DirPartyTable dirPartyTable;
DirPartyLocation dirPartyLocation;
DirPartyLocationRole dirPartyLocationRole;
LogisticsLocation logisticsLocation;
LogisticsLocationRole logisticsLocationRole;
LogisticsPostalAddress logisticsPostalAddress;
str isPrimary;
xlsApplication = SysExcelApplication::construct();
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
row = 1;
xlsWorkSheet.cells().item(row, 1).value("Custome ID");
xlsWorkSheet.cells().item(row, 2).value("Name or description");
xlsWorkSheet.cells().item(row, 3).value("Addresss");
xlsWorkSheet.cells().item(row, 4).value("Purpose");
xlsWorkSheet.cells().item(row, 5).value("Primary");
while select AccountNum from custTable
join Name from dirPartyTable
where dirPartyTable.RecId == custTable.Party
join IsPrimary from dirPartyLocation
where dirPartyLocation.Party == custTable.Party
join dirPartyLocationRole
where dirPartyLocationRole.PartyLocation == dirPartyLocation.RecId
join Type from logisticsLocationRole
where logisticsLocationRole.RecId == dirPartyLocationRole.LocationRole
join logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
{
row++;
xlsWorkSheet.cells().item(row, 1).value(custTable.AccountNum);
xlsWorkSheet.cells().item(row, 2).value(dirPartyTable.Name);
xlsWorkSheet.cells().item(row, 3).value(logisticsPostalAddress.Address);
xlsWorkSheet.cells().item(row, 4).value(enum2str(logisticsLocationRole.Type));
xlsWorkSheet.cells().item(row, 5).value(enum2str(dirPartyLocation.IsPrimary));
}
xlsApplication.visible(true);
}
Author:
Chirag Gupta
Microsoft Dynamics 365 AX Technical Consultant at IBM Bangalore
Date:
29-Jan-2020
Happy Learning !!
Thank you for sharing wonderful information with us to get some idea about it.
ReplyDeleteMicrosoft Dynamics AX Training
MS Dynamics AX Training
MS Dynamics Training in Hyderabad
Microsoft Dynamics AX Technical Training
Microsoft Dynamics AX Technical Training in Hyderabad
MS Dynamics Technical Online Training
MS Dynamics AX Technical Training in Hyderabad
MS Dynamics AX Online Training
D365 AX Online Training
Thanks for appreciation :)
Delete