Dot-walking in Scripts
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:
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.
Standard dot-walking functionality is not designed for requesting the values of the child table fields that are not inherited from the parent table. If you use dot-walking in this situation, the response will contain an error. The information on how to get the values of extended child table fields is available further in the article.
Get values of extended child tables fields with $$ operator
When working with scripts, you may come across a situation where you need to get the value of one of the extended child table fields that are absent from the parent table. If you use standard dot-walking in this case, you will see an error and will not get the required value. To solve this issue, the $$
operator has been developed. It allows you to search for the value among the extended child table fields.
For example, you need to get information about the caller's manager from a specific Task (task). Usually, the caller is an object from the User (user) table. However, in this case, the caller and their manager are objects of the Employee (employee) table that is a child of the User table and has an extended set of fields.
The caller's manager record is stored only in the Employee table. To get the ID of the manager, use the script that implements the attributes of the called record in the current element context.
In the example below, the current object is the object of the Task table. The $$
operator, if added before the Manager attribute name, allows you to reload the record in the context of the current Task table and call the required field of the child Employee table.
const current = new SimpleRecord('task');
current.get('170539993117855116'); // the task where the caller is a record of the Employee table.
ss.info(current.caller.$$manager);
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.