Dot Walking multiple levels using getReference.

HrishabhKumar
Kilo Sage

Can we dot walk more that 1 level using getReference in Client Script.

In my case I'm not able to do that, it is returning "undefined".

 

g_form.getReference('caller_id').manager.email
g_form.getReference('caller_id').department.name
 
Question:
1) Can we dot walk more that 1 level in getReference?
2) If yes, then how so? because in my case I'm getting undefined.
2 ACCEPTED SOLUTIONS

Allen Andreas
Administrator
Administrator

Hi @HrishabhKumar 

You are unable to dot-walk further than just the field on the table you getting the reference from.

Any further dot-walking would instead need to be done through GlideAjax and then passed back to the client.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

HrishabhKumar
Kilo Sage

Hi all,

After doing some research I have concluded the following.

1) We can only dot walk single level using getReference function.

2) If we need to dot walk up to multiple level then we should use GlideAjax or g_scratchpad.

View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Hi @HrishabhKumar ,

Actually you are using wrong syntax of g_form.getReference. Please check below script 

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

   //Type appropriate comment here, and begin script below  department
   var userref = g_form.getReference('caller_id', userLookup);
    function userLookup(userref) {
		alert("Name = " + userref.department);
        g_form.setValue('description', userref.department);
		g_form.update();
    }
   
}

SarthakKashyap_0-1717268875284.png

 

 

Here you can get the sys_id of caller's department(if present) in alert.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Hi @Community Alums ,

Thanks for you response.

This not a wrong syntax, this is one of the way to use getReference. FYI you can use getReference in two ways 

1) without callback fucntion (Synchronous)

    g_form.getReference('caller_id').manager.email

 

2) with callback function (Asyncronous & Recommended)

    The one you specified in the reply.

 

But anyways my question was can we do multiple level dot walking using getReference() function. I'm already able to get the sys_id of manager using the Synchronous method, I'm looking for the email of the manager, for that we will have to dot walk 2 levels.

first caller_id.manger

second caller_id.manager.email

According to my knowledge and confirmation from @Allen Andreas , We can only do one level dot walking in getReference function.

I hope my doubt is clear to you now.

 

Thanks & Regards

HRISHABH KUMAR

 

Allen Andreas
Administrator
Administrator

Hi @HrishabhKumar 

You are unable to dot-walk further than just the field on the table you getting the reference from.

Any further dot-walking would instead need to be done through GlideAjax and then passed back to the client.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hello @HrishabhKumar 

I just wanted to check back in and see how you're doing.

If I helped by answering your question please consider marking my reply as "Accept Solution".

Thanks and take care! 😀


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!