Dot walking using getReference in Client Script

rpoola
Tera Contributor

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;

        }

}

4 REPLIES 4

Deepak Ingale1
Mega Sage

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


Check if caller.u_approver is passing the sys_id.



Better and recommended   way to achieve this is GlideAjax.


https://community.servicenow.com/external-link.jspa?url=http%3A//wiki.servicenow.com/index.php%3Ftit...


Ganesh75
Giga Contributor

I think we can go upto one level of dotwalking  in getReference() method...

 

 

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);
}