1

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!

C. Griffin
  • 681
  • 1
  • 12
  • 32

2 Answers2

6

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);
    }
}
vukis
  • 381
  • 2
  • 10
  • This seems to be exactly what I was hoping to find, however, I am unsure of which method would be the best place to put this code. I tried placing it in the Form's init method, but it complains that the datasource isn't instantiated yet. – C. Griffin Aug 09 '12 at 13:56
  • Nevermind! It turns out that some fields were not present in the form's datasource, and when the .allowEdit() call was being made, it was sometimes trying to call that code on a nonexistent field. – C. Griffin Aug 09 '12 at 15:22
  • 1
    You are right the code was not efficient enough. I added an updated version with iterates through form's DS'es only. – vukis Aug 10 '12 at 05:36
0

I have a scenario in which I want to allow editing of ItemID in the InventJournalTrans form, based on an enum value in ANOTHER form. Is this possible?

Can args() class(parm method) be used to fetch the value of the checkbox? along with on the below condition in the active()?
My codes:

public int active()
{
int ret;
;

ret = super();

if([datasource table name].[Column 1 field name] == [Column1 value to
deactivate Column 3])
{
[datasource table name]_ds.object(fieldNum([datasource table name],
[Column 1 field name])).allowEdit(false);
}
else
{
[datasource table name]_ds.object(fieldNum([datasource table name],
[Column 1 field name])).allowEdit(true);
}

return ret;
}
Aditya
  • 2,876
  • 4
  • 34
  • 30
archie
  • 1