Purpose:
The purpose of this document is to demonstrate how we can Export Vendor GSTN details to excel X++ based on a business logic.
Product:
Dynamics 365 for Finance and Operations, Platform Update 9.
Development approach:
Customization through CODE, we need to Export Vendor GSTN details to excel
Development:
Create a class to export Vendor gstn details to excel
Please find the method definition as follows.
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class VendorGSTExportToExcel
{
public static void main(Args _args)
{
VendTable vendTable;
DirPartyTable dirparty;
LogisticsLocation location;
TaxInformation_IN taxInfo_IN;
VendName vendName;
str isprimary;
TaxRegistrationNumber_IN regnum;
MemoryStream memoryStream = new MemoryStream();
DocuFileSaveResult saveResult =
DocuFileSave::promptForSaveLocation("Vendor GSTR Data","xlsx", null, "excel create and export");
if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel)
{
using (var package = new ExcelPackage(memoryStream))
{
var currentRow = 1;
var worksheets = package.get_Workbook().get_Worksheets();
var CustTableWorksheet = worksheets.Add("Export");
var cells = CustTableWorksheet.get_Cells();
OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
System.String value = "Account Number";
cell.set_Value(value);
cell = null;
value = "Name";
cell = cells.get_Item(currentRow, 2);
cell.set_Value(value);
cell=null;
value="GSTR Number";
cell=cells.get_Item(currentRow,3);
cell.set_Value(value);
cell=null;
value="IS Primary";
cell=cells.get_Item(currentRow,4);
cell.set_Value(value);
while select * from vendTable
{
select * from dirparty where dirparty.RecId == vendTable.Party
join location where location.RecId == dirparty.PrimaryAddressLocation;
taxInfo_IN = TaxInformation_IN::findDefaultbyLocation(location.RecId);
regnum = TaxRegistrationNumbers_IN::find(taxInfo_IN.GSTIN).RegistrationNumber ;
vendName = vendTable.name();
SysDictEnum dictEnum = new SysDictEnum( enumnum(NoYesId));
isprimary = dictEnum.value2Label(taxInfo_IN.IsPrimary);
currentRow ++;
cell = null;
cell = cells.get_Item(currentRow, 1);
cell.set_Value(vendTable.AccountNum);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(vendName);
cell = cells.get_Item(currentRow, 3);
cell.set_Value(regnum);
cell = cells.get_Item(currentRow, 4);
cell.set_Value(isprimary);
}
package.Save();
}
memoryStream.Seek(0,System.IO.SeekOrigin::Begin);
//Download the file.
DocuFileSave::processSaveResult(memoryStream,saveResult);
}
}
}
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class VendorGSTExportToExcel
{
public static void main(Args _args)
{
VendTable vendTable;
DirPartyTable dirparty;
LogisticsLocation location;
TaxInformation_IN taxInfo_IN;
VendName vendName;
str isprimary;
TaxRegistrationNumber_IN regnum;
MemoryStream memoryStream = new MemoryStream();
DocuFileSaveResult saveResult =
DocuFileSave::promptForSaveLocation("Vendor GSTR Data","xlsx", null, "excel create and export");
if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel)
{
using (var package = new ExcelPackage(memoryStream))
{
var currentRow = 1;
var worksheets = package.get_Workbook().get_Worksheets();
var CustTableWorksheet = worksheets.Add("Export");
var cells = CustTableWorksheet.get_Cells();
OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
System.String value = "Account Number";
cell.set_Value(value);
cell = null;
value = "Name";
cell = cells.get_Item(currentRow, 2);
cell.set_Value(value);
cell=null;
value="GSTR Number";
cell=cells.get_Item(currentRow,3);
cell.set_Value(value);
cell=null;
value="IS Primary";
cell=cells.get_Item(currentRow,4);
cell.set_Value(value);
while select * from vendTable
{
select * from dirparty where dirparty.RecId == vendTable.Party
join location where location.RecId == dirparty.PrimaryAddressLocation;
taxInfo_IN = TaxInformation_IN::findDefaultbyLocation(location.RecId);
regnum = TaxRegistrationNumbers_IN::find(taxInfo_IN.GSTIN).RegistrationNumber ;
vendName = vendTable.name();
SysDictEnum dictEnum = new SysDictEnum( enumnum(NoYesId));
isprimary = dictEnum.value2Label(taxInfo_IN.IsPrimary);
currentRow ++;
cell = null;
cell = cells.get_Item(currentRow, 1);
cell.set_Value(vendTable.AccountNum);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(vendName);
cell = cells.get_Item(currentRow, 3);
cell.set_Value(regnum);
cell = cells.get_Item(currentRow, 4);
cell.set_Value(isprimary);
}
package.Save();
}
memoryStream.Seek(0,System.IO.SeekOrigin::Begin);
//Download the file.
DocuFileSave::processSaveResult(memoryStream,saveResult);
}
}
}
Comments
Post a Comment