Auto-populate fields in a request form based on user name lookup

Andy_B
Tera Contributor

I have created a request form for a catalog item.  At the top of the form is a name look up field.  Our ServiceNow instance has a table called sys_user which contains numerous columns including "Name", "Job Title", "Manager" and "Building".

What I would like to achieve is that the new request form has the same named fields ("Name", "Job Title", "Manager" and "Building") and when the requestor looks up a name and selects it the rest of the fields populate with the information from the user record in the sys_user table.

I am aware that the best method might be to create a Variable Set and I am aware of how to find things like column names (sys_user.manager for example) but that's about as far as I have got.

If possible, I would also like the ability to manually fill in these boxes if the name look up draws a blank...but bear in mind I have next to no scripting, coding or language skills so will be happy if the first part of my question works.

Any help massively appreciated.

 

Any help greatly appreciated.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

In this case all you need to do is create the other variables ("Name", "Job Title", "Manager" and "Building") which have the appropriate type that matches the fields on the sys_user_table.  On each of these variables, use the Auto-populate tab to select the name look up field, then select the matching field on the sys_user table in the Dot walk path drop-down/hierarchy. 

BradBowman_0-1727257760850.png

 

View solution in original post

6 REPLIES 6

amaradiswamy
Kilo Sage

Hi @Andy_B 

 

have you created the form already with those varaibles?

 

Do you want to know how to auto-populate these variables upon selection of a user name in Requested for variable? if yes, you can create an on-change client script which calls script include via GlideAjax and set the variable values.

 

Please try by understanding the below script:

https://www.servicenow.com/community/developer-articles/auto-populate-user-details-using-ajax/ta-p/2...

https://www.servicenow.com/community/developer-forum/autopopulate-user-details-onchange-of-user-name...

https://www.servicenow.com/community/itsm-forum/auto-populate-user-s-detail-on-catalog-item/m-p/2505...

 

So far I have created a form with a variable set containing variables "name", "job_title", "manager" and "building"... with "name" being a reference type variable with "User [sys_user]" as the Reference. (I have included 3 screen shots of the form, variable set and "name" variable details)

 

Thank you for the script URLs... looking at them I sort of understand what they are doing but I struggle with which bits to replace with what information from our SN instance.

There is a non-scripted approach also as suggested by Brad in one of the replies. Please follow those steps

 

I found below article which explains with an example use case

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

Brad Bowman
Kilo Patron
Kilo Patron

In this case all you need to do is create the other variables ("Name", "Job Title", "Manager" and "Building") which have the appropriate type that matches the fields on the sys_user_table.  On each of these variables, use the Auto-populate tab to select the name look up field, then select the matching field on the sys_user table in the Dot walk path drop-down/hierarchy. 

BradBowman_0-1727257760850.png