Tuesday, January 14, 2014

List all mandatory fields in the AOT

I wrote a job today that can list all the fields that are mandatory and belongs to particular tables that have particular configuration key. I thought I should share the code here, it might be helpful.
static void findMandatoryFields(Args _args)
{
 Dictionary dictionary;
 TableId tableId;
 Dicttable dictTable;
 DictField dictField;
 int fieldCounter;
 TextBuffer textbuffer = new TextBuffer();
 str fieldpath, previousText;


 dictionary = new Dictionary();

 tableId = dictionary.tableNext(0);

 while (tableId)
{
info(int2str(tableId));

tableId = dictionary.tableNext(tableId);
dictTable = new DictTable(tableId);
if (dicttable && dictTable.configurationKeyId() == configurationKeyNum(‘Bank’))
{
 fieldpath = “”;
 for (fieldcounter = 1; fieldcounter <= dictTable.fieldCnt(); fieldCounter++)
 {
 dictField = new dictField(tableId, dictfield.fieldCnt2Id(fieldCounter));
 if (dictField && dictField.mandatory() == true)
 {
 fieldpath += dicttable.name() + “:”+ dictField.name() + “\n”;
 }
 }
 previousText = textbuffer.getText();
 textbuffer.setText(previousText + fieldpath);
 }
 }

 textbuffer.toFile(“c:\\Test.txt”);
}

No comments: