Dot walking using getReference in Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 08:16 PM
Hi,
Following is my Client script where i am fetching details of reference field and copying to my current form fields. For one field I need to go two level dot walking which is not working.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.setValue('u_company', '');
g_form.setValue('u_billing_contact', '');
g_form.setValue('invoice_fequency', '');
g_form.setValue('u_approver', '');
return;
}
var caller = g_form.getReference('u_placement', placDetails);
}
function placDetails(caller) { //reference is passed into callback as first arguments
g_form.setValue('u_company', caller.u_company);
g_form.setValue('u_billing_contact', caller.u_billing_contact);
g_form.getReference('u_billing_contact', billingContact);
g_form.setValue('assigned_to', getApprover(caller.u_approver)); // This is not working as I need to fetch second level field value of reference field in my current form
}
function billingContact(caller){
g_form.setValue('invoice_fequency', caller.u_time_sheet_frequency);
}
function getApprover(caller){
var gr = new GlideRecord('x_vsng2_bullhorn_bh_approver'); //GlideRecord is not working it seeems
gr.addQuery('sys_id',caller);
gr.query();
if(gr.next()){
return gr.u_user;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 08:25 PM
Hi Ravikiran,
Dot walk does not work in client scripts, as you have done, you have got it via getReference, but there are better efficient ways to do it.
You need to use the GlideAjax to achieve your task.
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 08:37 PM
Check if caller.u_approver is passing the sys_id.
Better and recommended way to achieve this is GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2018 12:03 PM
I think we can go upto one level of dotwalking in getReference() method...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 08:44 AM
I just confirmed. One-level only:
function myCallbackFunction(user) {
console.info("user: " + user.name); /* works */
console.info("manager sysid: " + user.manager); /* works */
console.info("manager name: " + user.manager.name); /* does NOT work */
}
function getInfo() {
var user = g_form.getReference('requested_for', myCallbackFunction);
}