axaptadynamics-ax-2009ax

Dynamics AX 2009: How to programmatically allowEdit on Checkbox control


Essentially, this is what I'm faced with:

  1. I want to modify the InventTrans form
  2. By default, it has the entire InventTrans datasource set to AllowEdit = No
  3. I want to enable editing on ONE new Enum field (NoYes type)

Should I set the InventTrans datasource to AllowEdit = Yes and then painfully change 40+ fields in the datasource to be AllowEdit = No, OR is there a way to programmatically iterate through the fields of the datasource and set this property by name? (Please say there is, or an equally easy way to do this!)

Thanks in advance!


Solution

  • This is how I would try to disable editing to all fields:

    DictTable    dictTable;
    DictField    dictField;
    int          fldCnt;
    ;
    dictTable = new DictTable(tablenum(InventTrans));
    for (fldCnt = 1; fldCnt <= dictTable.fieldCnt() ; fldCnt++)
    {
        dictField = new DictField(tablenum(InventTrans), dictTable.fieldCnt2Id(fldCnt));
        info(strfmt("%1", dictField.id(),dictField.name()));
        InventTrans_DS.object(dictField.id()).allowEdit(false);
    }
    

    EDIT: Better approach to iterate through form's DS'es fields only:

    DictTable           dictTable;
    DictField           dictField;
    int                 fldCnt;
    QueryBuildFieldList qBFL;
    ;
    qBFL = InventTrans_DS.query().dataSourceTable(tablenum(InventTrans)).fields();
    for (fldCnt = 1; fldCnt <= qBFL.fieldCount() ; fldCnt++)
    {
        dictField = new DictField(tablenum(InventTrans), qBFL.field(fldCnt));
        info(strfmt("%1 %2 ", dictField.id(),dictField.name()));
        if(InventTrans_DS.object(qBFL.field(fldCnt))) //exception recVersion for example
        {
            InventTrans_DS.object(qBFL.field(fldCnt)).allowEdit(false);
        }
    }