To get the Data entity Fileds details in excel from Runnable class
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
internal final class TECGetDataEntityDetails extends RunBase
{
DialogField dataEntityName;
DMFEntityName entityName;
public Object Dialog()
{
Dialog dialog = super();
dialog.caption('Extract Data entity field properties.');
dataEntityName = dialog.addField(extendedTypeStr(DMFEntityName), '@SYS122449');
return dialog;
}
public boolean getFromDialog()
{
entityName = dataEntityName.value();
return super();
}
public void run()
{
DictTable dictTable;
DictField dictField;
int i, cnt;
DMFEntity dmfEntity;
select firstonly1 dmfEntity where dmfEntity.EntityName == entityName;
dictTable = new DictTable(Global::tableName2Id(dmfEntity.EntityTable));
cnt = dictTable.fieldCnt();
MemoryStream memoryStream = new MemoryStream();
using (var package = new ExcelPackage(memoryStream))
{
var currentRow = 1;
var worksheets = package.get_Workbook().get_Worksheets();
var dataEntityWorksheet = worksheets.Add("Export");
var cells = dataEntityWorksheet.get_Cells();
OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
System.String value = "Field Name";
cell.set_Value(value);
cell = null;
value = "Label ID";
cell = cells.get_Item(currentRow, 2);
cell.set_Value(value);
cell = null;
value = "Help Text";
cell = cells.get_Item(currentRow, 3);
cell.set_Value(value);
cell = null;
value = "Base Type";
cell = cells.get_Item(currentRow, 4);
cell.set_Value(value);
cell = null;
value = "Type";
cell = cells.get_Item(currentRow, 5);
cell.set_Value(value);
cell = null;
value = "String Length";
cell = cells.get_Item(currentRow, 6);
cell.set_Value(value);
for (i= 1; i <= cnt; i++)
{
dictField = new DictField(Global::tableName2Id(dmfEntity.EntityTable),dictTable.fieldCnt2Id(i));
currentRow ++;
cell = null;
cell = cells.get_Item(currentRow, 1);
cell.set_Value(dictField.name());
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(dictField.label());
cell = null;
cell = cells.get_Item(currentRow, 3);
cell.set_Value(dictField.help());
cell = null;
cell = cells.get_Item(currentRow, 4);
cell.set_Value(dictField.baseType());
cell = null;
cell = cells.get_Item(currentRow, 5);
cell.set_Value(dictField.type());
cell = null;
cell = cells.get_Item(currentRow, 6);
cell.set_Value(dictField.stringLen());
}
package.Save();
Dynamics.AX.Application.File::SendFileToUser(memoryStream, 'Field Prop.xlsx');
}
}
public static void main(Args _args)
{
TECGetDataEntityDetails getFieldProp = new TECGetDataEntityDetails();
// Prompt the dialog, if user clicks OK it returns true
if (getFieldProp.prompt())
{
getFieldProp.run();
}
}
}
Comments
Post a Comment