Deepak Negi
Mega Sage
Mega Sage

Let’s say you have a reference field like Caller on the Incident form. You want to trigger an onChange Client Script when the phone number of the selected caller changes.

Image 1.png

But when you try to create the script, you only see this:

Image 2.png

 

Yep — dot-walked fields like caller.phone_number are missing.

Solution: Use allow_references=true

To fix this, you just need to add a dictionary attribute to the Client Script’s field fieldname.

Steps:

 

  1. Go to the Dictionary Entry of the fieldname field.
  2. In the Attributes field, add allow_references=true

Image 3.png

 

3. Save the Dictionary Entry.

 

Image 4.png

 

That’s it. You’ve unlocked dot-walking in your onChange scripts.

Things to Keep in Mind

 

  • Upon doing this, the fieldname field will become mandatory and visible always, to fix this please add another attribute "allow_null=true" to fieldname

  • You may face a little lag while opening the client script form as it tries to pull the fields and their references
  • Haven't noticed any performance issues so far but be sure to check with the platform team before implementing this as this is a Global change

 

The allow_references=true attribute is a hidden gem that can level up your client scripting skills in ServiceNow.

Feel free to share any feedbacks or suggestions.

You can reach out to me on LinkedIn

 

Happy Learning!

Deepak Negi

Comments
Ian Mildon
Tera Guru

You can also do something like this catalog client script where I am querying the reference field "requester_name" which points to the "sn_hr_core_profile" table to pull back data from it and also to the "sys_user" table as there are dot-walked fields included

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var reqFor = getReferenceAdvancedPortal(g_form, "requester_name", "u_eid;u_infor_job_title;u_infor_dept_name;u_process_level;user.email;user.phone;user.sys_id;user.manager");

    //* extract entity from process level
    var reqEntIn = reqFor.u_process_level;
    var reqEntOut = reqEntIn.slice(7); //* trim first 7 characters from value

    //* update fields in the form
    g_form.setValue("requester_eid", reqFor.u_eid);
    g_form.setValue("requester_job_title", reqFor.u_infor_job_title);
    g_form.setValue("requester_department", reqFor.u_infor_dept_name);
    g_form.setValue("requester_entity", reqEntOut);
    g_form.setValue("requester_email_address", reqFor.user_email); //* reference to user profile
    g_form.setValue("requester_business_phone", reqFor.user_phone); //* reference to user profile
    g_form.setValue("subject_person", reqFor.user_sys_id); //* the hidden field that populates on RITM/SCTASK
    g_form.setValue("u_manager_approval", reqFor.user_manager); //* reference to user profile

}
Anton42
Tera Expert

Would be interesting to measure performance impact but is that even possible?

Version history
Last update:
‎04-09-2025 09:14 AM
Updated by:
Contributors