Fetch vendor 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 vendor address using X++ in AX 2012.
Create a AOT job and copy paste the below code to export vendor 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 vendor address using X++ in AX 2012.
Create a AOT job and copy paste the below code to export vendor address in excel.
// Project Name: PKA_WO67963_FetchCustomerVendorAddress
// Created by: Chirag Gupta (ibm.chirag)
// Created date: 18-Dec-19
// Summary: Fetch Vendor ID, Name or description, Address, Purpose, Primary
static void PKA_VendorAddress(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
int row;
VendTable vendTable;
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("Vendor 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 vendTable
join Name from dirPartyTable
where dirPartyTable.RecId == vendTable.Party
join IsPrimary from dirPartyLocation
where dirPartyLocation.Party == vendTable.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(vendTable.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 vendor 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 Vendor ID, Name or description, Address, Purpose, Primary
static void PKA_VendorAddress(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
int row;
VendTable vendTable;
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("Vendor 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 vendTable
join Name from dirPartyTable
where dirPartyTable.RecId == vendTable.Party
join IsPrimary from dirPartyLocation
where dirPartyLocation.Party == vendTable.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(vendTable.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 !!
Nice blog. You have provided such a useful informartion in this blog. Thanks for sharing.
ReplyDeleteMicrosoft Dynamics AX Training
Thanks for appreciation :)
Delete