Purpose:
The purpose of this document is to demonstrate how we can Export Customer 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 Customer GSTN details to excel
Development:
Create a class to export customer gstn details to excel
Please find the method definition as follows.
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class CustomerGSTExportToExcel
{
public static void main(Args _args)
{
CustTable custTable;
DirPartyTable dirparty;
LogisticsLocation location;
TaxInformation_IN taxInfo_IN;
CustName custName;
str isprimary;
TaxRegistrationNumber_IN regnum;
MemoryStream memoryStream = new MemoryStream();
DocuFileSaveResult saveResult =
DocuFileSave::promptForSaveLocation("Customer 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 CustTable
{
select * from dirparty where dirparty.RecId == CustTable.Party
join location where location.RecId == dirparty.PrimaryAddressLocation;
taxInfo_IN = TaxInformation_IN::findDefaultbyLocation(location.RecId);
regnum = TaxRegistrationNumbers_IN::find(taxInfo_IN.GSTIN).RegistrationNumber ;
custName = CustTable.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(CustTable.AccountNum);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(custName);
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 CustomerGSTExportToExcel
{
public static void main(Args _args)
{
CustTable custTable;
DirPartyTable dirparty;
LogisticsLocation location;
TaxInformation_IN taxInfo_IN;
CustName custName;
str isprimary;
TaxRegistrationNumber_IN regnum;
MemoryStream memoryStream = new MemoryStream();
DocuFileSaveResult saveResult =
DocuFileSave::promptForSaveLocation("Customer 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 CustTable
{
select * from dirparty where dirparty.RecId == CustTable.Party
join location where location.RecId == dirparty.PrimaryAddressLocation;
taxInfo_IN = TaxInformation_IN::findDefaultbyLocation(location.RecId);
regnum = TaxRegistrationNumbers_IN::find(taxInfo_IN.GSTIN).RegistrationNumber ;
custName = CustTable.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(CustTable.AccountNum);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(custName);
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