Code example ServiceNow - avoid dot walking

Code examples

Noncompliant code

It is not necessary to include the sys_id of a reference field when dot-walking, as in the following example:

var id = current.caller_id.sys_id; // Wrong

Compliant code

The value of a reference field is a sys_id. When you dot-walk to the sys_id, the system does an additional database query to retrieve the caller_id record, then retrieves the sys_id. This can lead to performance issues. Instead, use the statement.

var id = current.getValue('caller_id'); // Right

Last modified on Mar 19, 2021