Finance and operations

How to generate a list of field names and field properties

How to generate a list of field names and field properties

Today I quickly wanted to see which fields in the PurchLine table are mandatory. Purchline is a large table, so instead of checking the properties of each field, I quickly wrote a job that displays an info log of all the mandatory fields. I used the DictClass example script from Microsoft, and adapted it so that it generates a list with all the fields in the table.

This job can be easily changed to display the fields of other tables, simply change the tableName variable. It can also be changed to display other properties like ‘Allows edit on create’. For this you need to change the #DBF_Mandatory flag to another flag defined in the macro:
DictField Macro

This script uses a number of interesting things like macros, dictField, and dictTable. I’ll write separate posts for these topics soon. Until then, here is a simple job that lists all the fields in a table and their properties:

static void getMandatoryFields(Args _args)
    DictField   dictField;
    DictTable   dictTable;    
    FieldId     fieldId;
    int         nFlags;
    TableName   tableName = "PurchLine";
    dictTable   = new dictTable(tableName2Id(tableName));
    fieldId     = dictTable.fieldNext(0);    
    while (fieldId)
        dictField = new DictField(tableName2Id(tableName), fieldId);
        if (dictField)
            nFlags = dictField.flags();      
            if (bitTest(nFlags, #DBF_MANDATORY))
                info(strFmt("The field %1 is mandatory.",;
                //info(strFmt("The field %1 is not mandatory.",;
        fieldId = dictTable.fieldNext(fieldId);

The resulting info log should look something like this:
Mandatory purchline fields

Leave a Reply

Your email address will not be published. Required fields are marked *