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

Sandeep Rajput
Tera Patron
Tera Patron

@HrishabhKumar getReference only offers single level of dot walking. For multi-level dot walks you would need to use GlideAjax and do the multi-level in Script Include instead.

Maddysunil
Kilo Sage

@HrishabhKumar 

g_form.getReference() function is primarily used to fetch reference field values. However, it only retrieves the value of the referenced field, not its related fields. So, if you want to access fields on the referenced record, you'll need to use additional asynchronous calls.

 

// Get the caller_id reference
g_form.getReference('caller_id', function(user) {
    // Check if caller_id is defined
    if (user) {
        // Get the user's manager
        user.getReference('manager', function(manager) {
            // Check if manager is defined
            if (manager) {
                // Now, you can access the manager's email
                var managerEmail = manager.email;
                // You can also get manager's department name similarly
                manager.getReference('department', function(department) {
                    if (department) {
                        var departmentName = department.name;
                        // Now you have both manager's email and department name
                    } else {
                        // Handle if department is not defined
                    }
                });
            } else {
                // Handle if manager is not defined
            }
        });
    } else {
        // Handle if caller_id is not defined
    }
});

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

No it's not working.

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.

I've been looking for the answer to this question for hours. It was a hopeless answer, but I think it makes the most sense to edit it in its current form. Thank u.