Friday, October 9, 2020

D365 Datasource range lock / visibility

Microsoft Dynamics 365 for Operations & Financials

When adding ranges to datasources in code, you sometimes don't want the user to alter the range in any way. Sometimes it is also necessary to hide the applied range.

To lock or hide the range, use the status method of the QueryBuildRange class. The following code creates a hidden range of the field MyField to empty string.

QueryBuildRange qbrExampleRange; qbrExampleRange = MyDatasource_ds.query().dataSourceTable(tableNum(MyTable)) .addRange(fieldNum(MyTable, MyField)); qbrExampleRange.value(SysQuery::valueEmptyString()); qbrExampleRange.status(RangeStatus::Hidden);
The user will not be able to see or change the range of the field MyField.

Similarly the following code sets the field Department to "HQ". This time setting the range status to Locked.

QueryBuildRange qbrDepartmentRange; qbrDepartmentRange = MyDatasource_ds.query().dataSourceTable(tableNum(MyTable)) .addRange(fieldNum(MyTable, Department)); qbrDepartmentRange.value(SysQuery::value('HQ')); qbrDepartmentRange.status(RangeStatus::Locked);
The user will be able to see that there is a "HQ" filter on the Department field, but not able to remove it or change the value.