- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 09:19 AM
Hi,
Some help please not sure what am i missing here either of the user details are not populating at all.
These are the variables i created:
script include i created:
Catalog client script
Regards
CarolMa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 05:17 PM
In this scenario, if user selects Yes, then Auto-populate the Requested for field with the currently logged in user's id and make the field read-only. You can achieve this using UI policy.
If user selects no, then leave it as is.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 10:41 AM - edited 06-16-2025 10:42 AM
Hi @CarolMa6 ,
I have update my last response incase if you have missed it
update the client script as below
u are running this on Change of request_for_you variable only right?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestor = g_form.getValue('request_for_you');
if (request_for_you == 'Yes') {
var ga = new GlideAjax('SARBGetUserDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user', g_user.getUserID());
ga.getXMLAnswer(function(response) {
var UserDetails = JSON.parse(response);
g_form.setValue('name', UserDetails.userName);
g_form.setValue('p_number', UserDetails.pNumber);
g_form.setValue('department', UserDetails.department);
g_form.setValue('line_manager', UserDetails.managerName);
});
} else {
g_form.setValue('name', "");
g_form.setValue('p_number', "");
g_form.setValue('department', "");
g_form.setValue('line_manager', "");
}
}
if the line_manager and department are of string type
use
var SARBGetUserDetails = Class.create();
SARBGetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var UserDetails = {};
var ast = new GlideRecord("sys_user");
if (ast.get(this.getParameter("sysparm_user"))) {
UserDetails = {
"userName": ast.getValue('name'),
"pNumber": ast.getValue('user_name'),
"department": ast.department.getDisplayValue(),
"managerName": ast.manager.getDisplayValue(),
};
}
return JSON.stringify(UserDetails);
},
type: 'SARBGetUserDetails'
});
if they are of reference type use
var SARBGetUserDetails = Class.create();
SARBGetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var UserDetails = {};
var ast = new GlideRecord("sys_user");
if (ast.get(this.getParameter("sysparm_user"))) {
UserDetails = {
"userName": ast.getValue('name'),
"pNumber": ast.getValue('user_name'),
"department": ast.getValue('department'),
"managerName": ast.getValue('manager'),
};
}
return JSON.stringify(UserDetails);
},
type: 'SARBGetUserDetails'
});
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 09:28 AM - edited 06-16-2025 09:32 AM
Hi @CarolMa6
Use "Auto-populate" feature to populate the related values. No need to use scripts and easy to maintain.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 09:30 AM
you can use Auto populate feature and no scripting is required
Auto-populate a variable based on a reference type variable (Utah)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 09:50 AM
Not sure how will this solution work because auto populating the fields is dependent on the "request_for_you" variable which is a "yes/no" answer. If answer is yes, the form should auto populate the logged in user details if answer is no, then user needs to populate the requested for name then the username, department and line manager should auto populate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 05:17 PM
In this scenario, if user selects Yes, then Auto-populate the Requested for field with the currently logged in user's id and make the field read-only. You can achieve this using UI policy.
If user selects no, then leave it as is.
Regards,
Siva