Wednesday, June 16, 2010

Getting the names of all the tables in AX

Getting the names of the TABLES


static void FindTables(Args _args)
{
    Dictionary      dictionary;
    TableId         tableId;
    ;
    dictionary = new Dictionary();
    tableId = dictionary.tableNext(0);
    while (tableId)

    {
        info(tableid2Name(tableId));
        tableId = dictionary.tableNext(tableId);
    }
}
The Output will be as follows



Displaying the names of the files in the directory

To display names of the files in directory

static void ShowFileNameinDirectory(Args _args)
  {
      int           handle;
      FilePath      filePath;
      FileName      FileName;
      ;
      filepath = "D:\\Cole Hersee Reports";
      [handle,filename] =
       WinAPI::findFirstFile(filepath + \\*.xls);
      while (filename)
      {
          info(filepath + "\\" + filename);
          filename = WinAPI::findNextFile(handle);
      }

      WinAPI::findClose(handle);
  }

How to find the mandatory fields in the table manually

USING SYSDICTTABLE CLASS

static void mandatoryFieldsOfATable(Args _args)
{
    SysDictTable sysDictTable;
    SysDictField sysDictField;
    TableId tableId;
    Counter counter;
    ;
    sysDictTable = new SysDictTable(tablenum(CustTable));
    for(counter = 1;counter <= sysDictTable.fieldCnt(); counter++)
   {
        sysDictField = new sysDictField(sysDictTable.id(), sysDictTable.fieldCnt2Id(counter));

       if(sysDictField.mandatory())
                 info(sysDictField.name());
    }
}

The output of the above code will be