- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 11:47 PM
Hello,
In the catalog item variables if the user selected the name i want to autopopulate the location and company both are reference field in the sys_user table. Can anyone sugget the scriptinclude and client acript to autopulate.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:04 AM
Try the below trick.
- Define your user variable. Sample below as "Requested for"
- Create the Location variable
- At the section "Auto-populate", set similar to the below screenshot.
You can do the same for the Company variable.
Let me know if it works for you!
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:19 AM - edited 10-11-2023 12:19 AM
As you mentioned. location & company fields are of type "Reference".
It should not populate sys_id.
Can you check , both variables on catalog item are of type "reference" or Single line text.
If its single line text then update script include below :
if (grUser.next()) {
/*4. If user present then store values in JSON object */
result.location = grUser.location.name; //updated
result.company = grUser.company.name; //update
}
/*5. Stringify the object and then return */
return JSON.stringify(result);
OR you can go with Auto-populate option suggested by @Tai Vu you just need to dot-walk on "Name" field.
like location.name & company,name
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:14 AM
Tried your suggested trick but sys_id is populating in the variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:16 AM
You mean we are able to get the Location and Company from the User Profile. However the Location and Company variables are populated as sys_ids?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:07 AM
As already stated by our colleague in the below script includes and client script , if there are only two fields and less data you can also try to use getreference() function however there is a disadvantage to it related to performance :
You can refer below links :
https://www.servicenow.com/community/developer-forum/getreference-best-practice-or-not/m-p/1522500
Please mark helpful/correct if my response helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:08 AM
Hi @Servicenow de11 ,
Pls look at the below link,
Mark my answer helpful & accepted if it helps you.
Thanks,
Danish