First Names and Last Name auto populated in variables : catalog item

asasas
Kilo Contributor

I have created variable : First Name and last Name variables in catalog item

What I need is logged in user name should be auto populated in First Name and Last Name variables field

I am able to auto populate the user name in reference variable , but i need in not reference field.

1.PNG

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Allu,



Can I ask what the use case is for this since the name is available via the reference field?



You can use a default value for the variable like this:



javascript:gs.getUser().getFirstName();



javascript:gs.getUser().getLastName();



http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


shivam_singhal
ServiceNow Employee
ServiceNow Employee

Hi Allu,



you can do this by writing a simple onLoad catalog client script :



function onLoad() {


        g_form.setValue('fname',g_user.firstName);


          g_form.setValue('lname',g_user.lastName);


}



Screen shots for your reference:


1. Write a Catalog client script like this.


Screen Shot 2016-10-07 at 10.13.34 PM.png



2.


Screen Shot 2016-10-07 at 10.14.40 PM.png



Thanks,
Shivam



PS: Mark Correct/Helpful /Like based on the effect of response.


shivam_singhal
ServiceNow Employee
ServiceNow Employee

Hi Allu,



Please mark the correct answer if we solved your problem, it will help others who will stuck in the same use case.



Thanks,


Shivam