Dot-walking provides access to fields of related tables from a form, list, or script. A table can contain references to other tables, and the fields in these tables can be accessed by dot-walking.

Dot-walking builds a chain of field names separated by dots. For example, incident.assigned_user.company references to the company of the user assigned to the incident.

This article describes how the dot-walking functionality is used in scripts. See the Dot-walking article to learn more about the functionality.

For example, the script below will return the email of the person responsible for the current assignment group:

dot-walking
const current = new SimpleRecord('itsm_incident');
current.get('158557395619812771');
ss.info(current.assignment_group.responsible.email);
// Info: john.doe@example.com

To speed up the script execution, use the getValue(property) method to get the values of the fields of the Reference type instead of using dot-walking.

As an example, it is preferable to use the current.getValue('reference_field') structure instead of current.reference_field.sys_id one.

Process the Context


For example, you are an admin and work with the Task records. You need to get information about the caller of a specific task. Usually, the caller is an object from the User (user) table. However, in this case, the caller is an object from the Employee (employee) table that is a child of User and has an extended set of fields.

The phone number of the caller's manager is stored only in the Employee table. To get the phone number of the manager, use the script that implements the attributes of the called record in the current element context. In this example, the current object is the object of the Task table. 

The Caller field refers to the User table. To get the attribute value of the Employee child table, reload the record in the context of the current Task table. To do so, add '$$' symbols before the attribute name you are calling.

Context Processing
const current = new SimpleRecord('task');
current.get('161157603117108419'); // a task record where a caller is an Employee object.
ss.info( "VIP: " + current.caller.$$vip) // Info: VIP: true
ss.info( "Non-existing attribute: " + current.caller.$$NonExisting) // Info: Non-existing attribute: null
if (!!current.caller.$$manager) {
  ss.info("Manager: " + current.caller.manager.getDisplayValue()) // Info: Manager: John Doe
}

When calling a non-existing attribute, the script returns null.

When applying this script to a record where the caller is not the object of the Employee table, the script returns null to all requests.

  • No labels