getReference client script HELP!

orlando_f
Kilo Contributor

Hi SN Guru's

 

Hope you can help with this request. Using the "getReference" call, I'm trying to take a users email address value (from the user referenced table) on the Change Request form and insert the email address value of a selected user straight into another field (new field) on the form using g_form.getReference method and object.

 

Thanks

 

1 ACCEPTED SOLUTION

To verify, are you wanting to copy the email of the requested_by to the description when the requested_by is changed?   Does this work for you, made a couple tweaks:



var refemail = g_form.getReference('requested_by', setDesc);



    function setDesc(refemail) {


          g_form.setValue('description', refemail.email);


    }


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Orlando,



You can dotwalkin the reference field and get the email address of the user without any script.


You can refer the OOB client script If you want to "(BP) Set Location to User" to know more about the GetRef method.



Please let me know if you have any questions.



Thanks,


Pradeep Sharma


Please refer the below wiki link for further info on Dot-Walking


http://wiki.servicenow.com/index.php?title=Dot-Walking



NOTE:If you go by this way you need not use the scripting



Thanks,


Pradeep


AnishSasidharan
Mega Expert

g_form.getReference('caller_id').user_email;



Once you have performed the "getReference", you have a glide record and can dot-walk it to the field values without further server lookups.





harikrish_v
Mega Guru

Hi Orlando,



Another thing you can do is, instead of creating a new field for email on the form, you can personalize your form layout and using this reference field to User table, you can perform a dot walk and add the email field from the user table itself on your form. This way, that field will be auto-populated, whenever you make an entry in the reference field, without any coding.



You can check section 3 in this link on how to do dot walking:-http://wiki.servicenow.com/index.php?title=Dot-Walking



Thanks & Regards,


Hari