Skip to main content

Notifications

Announcements

No record found.

Allow Edit of a specific field and to disable complete Form Datasource

Recently I came across a requirement in which I need to disable complete datasource but make a single field editable.

In this scenario, the traditional way of making datasource disable by using allowedit(false) and enabling a field will not work since allowedit() method will disable complete datasource. Even we cannot make just the control enabled since whole datasource is disabled.

The best way here is to disable each and every field and enable the specific field.

We no need to write disabling logic for every field nor to write some loop here to loop through all the fields of table and disable.

The Method:
We can use one standard method which serves our purpose. Below is the method for the same.

allowEditFieldsOnFormDS_W(<FormDataSource>, <boolean>)

This method just requires the FormDataSource as a parameter and a boolean parameter to allow editing.

Understanding of method:

public static void allowEditFieldsOnFormDS_W(FormDataSource _dataSource, boolean _allowEdit)
    {
        var dictTable = new DictTable(_dataSource.table());
        int         cx, idx;

        for (cx = 1; cx <= dictTable.fieldCnt(); cx ++)
        {
            DictField dictField = dictTable.fieldObject(dictTable.fieldCnt2Id(cx));

            if (! dictField.isSystem())
            {
                for (idx = 1; idx <= dictField.arraySize(); idx++)
                {
                    FormDataObject dataObject = _dataSource.object(fieldId2Ext(dictField.id(), idx));
                    if (dataObject)
                    {
                        dataObject.allowEdit(_allowEdit);
                    }
                }
            }
        }
    }

This method as I said above takes, FormDataSource and a boolean as a parameter and based on the field count, this loops through all the fields and if it is not a system field like RecId or Partition, then it gets the FormDataObject from field and sets the form datasource field's allow edit property. This method is found in Global class.

This also works, let's say if you have a requirement to disable the complete SalesLine and some warehouse related or other datasource related fields should be enabled, then also allowedit() method will not work. This works in that scenario.

Implementation:

We just need to call this method with required parameters and then whichever field we need to be editable, make that field to be editable. Below is an example.
allowEditFieldsOnFormDS_W(dirPartyTable_ds, false);
      dirPartyTable_ds.object(fieldNum(DirPartyTable, KnownAs)).
           allowEdit(true);

Thats all for now!





Happy Learning!


Comments