Axaptapedia is now maintained by AgileCadence For more information please click here.
Accessing datasource field properties
Often it is useful to be able to access the datasource field properties on a form through X++. This is essential for modifying the allowEdit property at run-time for example.
The following code can be used to set the allowEdit of the InventTable.ItemName field on a form.
<xpp> FormDataObject fldItemName; boolean allowEdit = false; //This would set according to some criteria
fldItemName = inventTable_DS.object(fieldNum(InventTable,ItemName)); fldItemName.allowEdit(allowEdit); </xpp>
Download this project for an example form showing this technique.
To prevent editing code when you add fields to the table, call the fieldproperties using the dictionary classes: <xpp> FormDataObject fldItemName; boolean allowEdit = false; //This would set according to some criteria SysDictTable dictTable = new SysDictTable(this.table()); FieldId currentFieldId;
for (currentFieldId = dictTable.fieldNext(0); currentFieldId; currentFieldId = dictTable.fieldNext(currentFieldId)) {
fldItemName = this.object(currentFieldId); if (fldItemName) fldItemName.allowEdit(allowEdit);
} </xpp> Code called from a method on the datasource itself. Check the fldItemName for null, System fields (eg 'ModifiedBy') are not present in the datasource, but is in the table.