Dot-walking provides access to fields of related tables from a form, list, or script. The table may contain references to the 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 (periods). For example, incident.assigned_user.company references to the company of the user assigned to the incident.
Dot-walking in scripts
can use this feature in your scripts by invoking the appropriate syntax.
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.
Context processing
An example of a business case:
The administrator works with Task records. At some point, it is necessary to get information about a specific task caller (who is, technically, should be an object of the User table). After getting the information, the administrator realizes that the caller is an object of the Employee table, which is a child of the User table and has an extended field set.
The administrator needs to get the manager's phone of this employee. This information exists in the Employee table record of this user, but is not mentioned in the User table. To get the phone number, a script can be used. The script will implement the attributes of the calling record in the current element context.
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
}
In this example, the current object is the object of the Task table.
So, to get the values of the attributes existing only in the child tables, you need to reload the record within the necessary table context. To do this, add '$$' symbols before the attribute name you are calling.
When you do this, the record reloads within the necessary table context, and all fields related to this table become available.