Modify Standard Change Templte - Pre-populate the change request Values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 12:18 PM - edited 09-23-2024 01:53 PM
Hi All,
Whenever a user selects the value from the lookup field "Template To Modify," populate the Change Request Values fields along with Description and Category.
I tried with a catalog client script on "Modify a Standard Change Template" record producer and a script include, but it's not working. I need help.
-***On change catalog Client script on Template of Modify variable**
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Add info message for debugging
g_form.addInfoMessage('Template to modify selected. Fetching data for template: ' + newValue);
// Call GlideAjax to retrieve the template details from the server
var ga = new GlideAjax('StandardChangeTemplateUtil'); // Reference to the Script Include
ga.addParam('sysparm_name', 'getTemplateDetails'); // Function name in Script Include
ga.addParam('sysparm_template_id', newValue); // Pass the selected template sys_id
ga.getXMLAnswer(function(response) {
if (response) {
var templateData = JSON.parse(response);
if (templateData.error) {
g_form.addErrorMessage(templateData.error);
} else {
// Populate fields with the retrieved template data
g_form.setValue('change_request_values', templateData.change_request_values); // Change Request values field
g_form.setValue('short_description', templateData.short_description); // Other fields as needed
// g_form.setValue('description', templateData.description);
}
} else {
g_form.addErrorMessage('No data received for the selected template.');
}
});
}
Script Include
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Add info message for debugging
g_form.addInfoMessage('Template to modify selected. Fetching data for template: ' + newValue);
// Call GlideAjax to retrieve the template details from the server
var ga = new GlideAjax('StandardChangeTemplateUtil'); // Reference to the Script Include
ga.addParam('sysparm_name', 'getTemplateDetails'); // Function name in Script Include
ga.addParam('sysparm_template_id', newValue); // Pass the selected template sys_id
ga.getXMLAnswer(function(response) {
if (response) {
var templateData = JSON.parse(response);
if (templateData.error) {
g_form.addErrorMessage(templateData.error);
} else {
// Populate fields with the retrieved template data
g_form.setValue('change_request_values', templateData.change_request_values); // Change Request values field
g_form.setValue('short_description', templateData.short_description); // Other fields as needed
// g_form.setValue('description', templateData.description);
}
} else {
g_form.addErrorMessage('No data received for the selected template.');
}
});
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:59 PM
Hello @MR1,
For similar kind of issue, Please refer to the below link:
https://www.servicenow.com/community/developer-forum/standard-change-template-variable-update-change...
If it is helpful, please mark it as helpful and accept the correct solution.
Thanks & Regards,
Abbas Shaik