Background

When selecting data from SQL in X++, you can provide a field list to limit the amount of data fetched from SQL. This improves the performance of the select statement; but risks that downstream consumers expects the data to be available, and might make wrong decisions.

Example:

SalesLine salesLine;
select SalesId from salesLine;
info(strfmt("%1", salesLine.ItemId));

This compiles perfectly, but will never write out anything, as salesLine.ItemId remains blank.

It is not possible for the compiler to detect these issues - as for example salesLine could be passed to another method.

Instead we have a runtime check.

Enabling the runtime check

Enabling the runtime checker can be quite useful before running unit tests to flush out any logical mistakes.
!!!DO NOT DO THIS ON A PRODUCTION SYSTEM!!!

  1. Run this SQL script:
update SYSGLOBALCONFIGURATION
set Value = 1
where Name = 'CHECKINVALIDFIELDACCESS'
  1. Restart the AOS

Investigating errors

The SalesLine example above will throw an exception when the runtime checker is enabled.

The typical fix would be to add ItemId to the field list, or perhaps remove the field list all together. In some cases our logic is designed to handle non-selected fields (they have their null-value), here you can instruct the system to not perform the check.

You do that be adding this line:
salesLine.checkInvalidFieldAccess(false);

THIS POST IS PROVIDED AS-IS; AND CONFERS NO RIGHTS.