Can I use Dot.Walk to get the sys_id of a reference field ?

kiki330611
Kilo Expert

Hi Everyone,

I have three tables here, one is staff duty table, another one is staff table and the other user table.

On staff duty table there is a name field reference from staff table and on staff table there is a username field reference from user table.

Now I want to use dot.walk to go from staff duty table to staff table and get the value of the username field on staff table.

Is there any code in GlideRecord that I can use?

I tried something like this but both didn't work:

gr.u_staff_name.u_username.getValue()

gr.getValue('u_staff_name.u_username')

Somehow the first one works if I replace getValue() with getDisplayValue()... But I need the actual value of that username field in staff table.

Anyone know how to do this?

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Kiki,



How about gr.u_staff_name.u_username



The key thing to remember is that the value of a reference field IS a sys_id. You do not need to go all the way to the sys_id field in nearly every case. So,



gr.u_staff_name.u_username.sys_id would be a waste of time.



Hope that helps.


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Kiki,



How about gr.u_staff_name.u_username



The key thing to remember is that the value of a reference field IS a sys_id. You do not need to go all the way to the sys_id field in nearly every case. So,



gr.u_staff_name.u_username.sys_id would be a waste of time.



Hope that helps.


I knew it's that easy but just couldn't get it done properly...


Thanks so much!!!


jcote
Giga Expert

The value of a reference field is the sys_id of the referenced record.



So to get the value of the sys_id of the user on the User [sys_user] table from the Staff duty table. You'd do the following:



gr.u_staff_name.u_username;



Here's how it would look, you can fill in the field names for the below dot walking structure:


[staffduty GlideRecord object].[reference field of staff table].[reference field of sys_user];



If that doesn't work perfectly, stick a ".sys_id" at the end of it like so:


[staffduty GlideRecord object].[reference field of staff table].[reference field of sys_user].sys_id;



Can you post your entire query?


Problem solved! Thanks so much!