Auto-populate User in Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2025 10:14 PM
Hi,
I have created one record producer. In the record producer, there is a field called Impacted User. It will be auto-populated based on the current logged-in user. If want, after populating impacted user can be edited. After populating the Impacted User, the next field Location will be auto-populated based on the Impacted User field. To auto-populate the Impacted User field, I used the following code :
javascript:gs.getUserID();
in the Default value of the Impacted User variable in the record producer. It is working fine. But for some demo users I created, initially the Impacted User field gets populated and the location will be auto-populating based on this. But if I edit the Impacted User field, the location is not getting populated. The location field list is showing users list in that case.I created some demo users. So if I log in as one demo user and edit the impacted user to another demo user that I created this situation happens. In all other situations, it is working fine. Why this happens? The initial image attached is working when the demo user initially login. But when the impacted user is changed, the loxation field is not getting auto-populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2025 11:08 PM
Hello, how do you populating Location field? Please share a screenshot. Has Demo User4 location field populated in his user record?
For your requirement, you can use Auto-Populate tab on the variable.
Dependent question: Impacted user field
Reference should be auto-populated to: User table [sys_user]
Dot walk path: Location.country
In my screenshot below I am using Requested for field, works fine.
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 01:35 AM
In my case, end user ( no role) can create request for other end user. For them, the location field is not auto-populating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 01:53 AM
Users without roles are not allowed to see data in User [sys_user] table.
This is controlled by out-of-box ACL 'sys_user.*':
- Description: Users can read their own user records and users with a role can read other user records
- Sys ID: 7df70f39c0a801661fb9e679f553c760
Try to create new field ACL for sys_user.location without conditions. However this solution might be considered as a security issue.
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 06:57 AM
you can have the 2nd variable auto-populated based on 1st variable using this feature
Auto-populate a variable based on a reference type variable (Utah)
OR
you can use onChange catalog client script and set the location on change of user
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('location'); // location variable name here
var ref = g_form.getReference('impacted_user', callBackMethod); // impacted user variable name
}
function callBackMethod(ref) {
if (ref.location)
g_form.setValue('location', ref.location); // location variable name here
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader