- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:38 PM
Hi Community,
I need your help with debugging auto populating scripts.
I have create script include and client script to auto populate manager field when user is selected on the form.
When I select user while raising form, the manager name is populated successfully. But after submission of ritm, the manager name is disappeared.
Also, Client script is selected to Run on Catalog item, RITM, Catalog task. So, I'm confused what is causing this issue.
Please find below scripts i've used:
Script include:
// Script Include: ManagerLookup
var ManagerLookup = Class.create();
ManagerLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerName: function () {
var userId = this.getParameter('sysparm_user_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
return userGR.manager.getDisplayValue();
}
return '';
},
type: 'ManagerLookup'
});
Client Script:
// Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || newValue === oldValue) {
return;
}
// Get the selected user's Sys ID
var userId = g_form.getValue('variables.employee_to_offboard');
// Call the Script Include using GlideAjax
var ga = new GlideAjax('ManagerLookup');
ga.addParam('sysparm_name', 'getManagerName');
ga.addParam('sysparm_user_id', userId);
ga.getXMLAnswer(function (answer) {
// Assuming your manager field is named 'manager' on the catalog item
g_form.setValue('variables.manager', answer);
});
}
Please suggest what I am missing here?
Thanks in Advance,
Hritik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:43 PM - edited 02-01-2024 11:46 PM
Hi @Hritik
Is the manager field a reference field or String field, if its reference field, in Script Include just return user.manager . If this is not the case then if you have a variable within the variable set that has the same name as the internal name of the variable set, the value will not be saved in the RITM
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:43 PM - edited 02-01-2024 11:46 PM
Hi @Hritik
Is the manager field a reference field or String field, if its reference field, in Script Include just return user.manager . If this is not the case then if you have a variable within the variable set that has the same name as the internal name of the variable set, the value will not be saved in the RITM
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 12:12 AM
Hi @Hritik ,
I am assuming if you are using Utah or further version, easy configuration will be help you on this (Auto-populate feature for catalog item variables) instead of using scripting way. For more information refer this blog.
Kindly mark helpful/accepted if it helps you.
Regards,
Priyanka Salunke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 12:31 AM
Hi Priyanka,
Thanks for the reference. I used Auto populate feature, but I encountered another problem.
Could you please and help me here ? Auto poulation does not work if we create request via REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 08:25 AM
@Hritik ,
As per the research, unfortunately, Auto population feature does not work if request is created via REST API currently. Servicenow might enhanced it in upcoming release. You need to use scripting way (by Business rule) for now.
Kindly mark helpful/accepted if it assists you.
Regards,
Priyanka Salunke