- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 09:43 AM
Hello Everyone,
I am working on a requirement in the Incident table where I need to verify whether the selected Configuration Items (CMDB_CI) have a u_reopen_list field set to true. If true, I want to display an alert with the names of those records.
Requirement:
1️. Incident Table (incident)
- Added a Glide List field: u_glide_list
- Target Table: cmdb_ci
2️. CMDB Table (cmdb_ci)
- Added a Choice Field: u_reopen_list (Values: true / false)
3️. Functionality Needed:
- When users select multiple records in the u_glide_list field, I need to check if any of them have u_reopen_list = true.
- If true, show a pop-up with the names of those records.
- If false, no alert should appear.
- This should trigger onChange of u_glide_list.
- The logic should be handled using a Script Include (server-side) and a Client Script (client-side).
What I Have Done So Far?
Created a Script Include (CheckReopenStatus)
var CheckReopenStatus = Class.create();
CheckReopenStatus.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkReopen: function() {
var glideList = this.getParameter('sysparm_glideList'); // Get selected values
if (glideList) {
return JSON.stringify([]); // Return empty array if nothing selected
}
var sysIds = glideList.split(','); // Convert to an array
var results = [];
var grCMDB = new GlideRecord('cmdb_ci');
grCMDB.addQuery('sys_id', 'IN', sysIds);
grCMDB.addQuery('u_reopen_list', 'true'); // Check for reopen = true
grCMDB.query();
while (grCMDB.next()) {
results.push(grCMDB.getValue('name') + " - Reopen is True");
}
return JSON.stringify(results); // Return names
},
type: 'CheckReopenStatus'
});
Created a Client Script (onChange on u_glide_list)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var glideList = g_form.getValue('u_glide_list'); // Get selected values
if (glideList) {
var ga = new GlideAjax('CheckReopenStatus');
ga.addParam('sysparm_name', 'checkReopen');
ga.addParam('sysparm_glideList', glideList);
ga.getXMLAnswer(function(response) {
var messageArray = JSON.parse(response);
if (messageArray.length > 0) {
alert(messageArray.join("\n")); // Show alerts
}
});
}
}
Issue:
- The script is not showing an alert when the condition matches.
- I have ensured that the Script Include is Client Callable, but it's still not working.
- No error appears, but nothing happens when I change the Glide List field.
Question:
- What could be missing in my setup?
- Is there a better approach to achieve this requirement?
- How can I debug this issue in ServiceNow?
I would appreciate any guidance or corrections. Thank you in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:29 AM - edited 02-27-2025 11:06 AM
Hi @satyamc ,
The approach looks fine however i found few mistakes in code.
1. If(glidelist) -> It should be if (!glidelist) ----- Its should go inside the loop when there is no value.
2. In Client Side I believe you don't need to parse it since in server side it's not an object.
3. while (grCMDB.next()) {
results.push(grCMDB.getValue('name') + " - Reopen is True");
} //// Why are you concatenating " - Reopen is True". It's Not required until you want to show specific alert message.
For debugging use:
1. gs.info (server Side) to check if glidesit array is storing proper values. If yes, then check values are correctly pushing in your result array again by gs.info()
2. g_form.addInfomessage(response) (Client Side) to check what is your response showing or try to write your code in Background Script for quick testing to check script include code.
Please refer the snip on similar lines and make changes accordingly.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:29 AM - edited 02-27-2025 11:06 AM
Hi @satyamc ,
The approach looks fine however i found few mistakes in code.
1. If(glidelist) -> It should be if (!glidelist) ----- Its should go inside the loop when there is no value.
2. In Client Side I believe you don't need to parse it since in server side it's not an object.
3. while (grCMDB.next()) {
results.push(grCMDB.getValue('name') + " - Reopen is True");
} //// Why are you concatenating " - Reopen is True". It's Not required until you want to show specific alert message.
For debugging use:
1. gs.info (server Side) to check if glidesit array is storing proper values. If yes, then check values are correctly pushing in your result array again by gs.info()
2. g_form.addInfomessage(response) (Client Side) to check what is your response showing or try to write your code in Background Script for quick testing to check script include code.
Please refer the snip on similar lines and make changes accordingly.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards,
Rohit