Get System Table Row's with Type and Description in WordDocument through Job in Ax


Description:-

Here we will Create Dynamically Word File and dynamically retrieve all row’s from table with Type and Description and Display in Word File. For that Create Job and assign System table name to Display All rows with Description in Word File.

Here I have used “CustTable” to Retrieve all Rows from CustTable.

Code:-

static void writeTableInWord(Args _args)
{
  COM   app, document, wordDocument;
  COM   range, tables, table;
  COM   cell, cells, rows, row, shading, font, paragraphs;
  inti, j;
  sysDictTablesysDictTable = newSysDictTable(tableNum(CustTable));
  sysDictFieldsysDictField;
  ;

  app = new COM('Word.Application');
  app.visible(true);

  document     = app.Documents();
  wordDocument = document.add();
  wordDocument.activate();

  range = wordDocument.range(0,0);
  tables = wordDocument.tables();

  //Add the table
  table = tables.add(range , 1, 3);
  table.style('Table Grid');

  //Write to cells
  cell = table.cell(1,1);
  range = cell.range();
  range.text('Field Name');

  cell = table.cell(1,2);
  range = cell.range();
  range.text('Type');

  cell = table.cell(1,3);
  range = cell.range();
  range.text('Description');

  for (i = 1; i<= sysDictTable.fieldCnt(); i++)
  {
    sysDictField = sysDictTable.fieldObject(i);
    if (sysDictField&& !sysDictField.isSystem())
    {
      //Add a row to the table
      rows = table.rows();
      rows.add();

      cell = table.cell(i + 1, 1);
      range = cell.range();
      range.text(sysDictField.name());

      cell = table.cell(i + 1, 2);
      range = cell.range();
      range.text(enum2str(sysDictField.baseType()));

      cell = table.cell(i + 1, 3);
      range = cell.range();
      range.text(sysDictField.help());
    }
  }

  //Formatting first row of the table
  //Get the first row
  row = rows.first();
  cells = row.cells();
  cells.verticalAlignment(1); //Middle
  row.setHeight(20, 2);
  shading = row.shading();
  shading.backgroundPatternColor(10526880); //Grey 375
  range = row.range();
  font  =range.font();
  font.bold(1); //Bold
  paragraphs = range.paragraphs();
  paragraphs.alignment(1); //Center
}

Related Posts

Previous
Next Post »

Thanks for comments.....