Display the List of affected CIs of Incident in a custom Field in Incident Record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 12:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 11:23 PM
Hi @MihirG
can you use the below revise script :-
Client Script :-
function onLoad() {
var finalArray = [];
var ga = new GlideAjax('CIsIncident');
ga.addParam('sys_parm_name', 'affectedCIs');
ga.addParam('sys_parm_INCsys', g_form.getValue('sys_id'));
ga.getXMLAnswer(callback);
function callback(res) {
if (res) {
try {
var obj = JSON.parse(res);
for (var i = 0; i < obj.length; i++) {
finalArray.push('Task: ' + obj[i].taskName + ', CI: ' + obj[i].name);
}
g_form.setValue('u_list_of_associated_cis', finalArray.join('\n'));
} catch (e) {
console.error('Error parsing response:', e);
}
} else {
console.warn('No associated CIs found.');
g_form.setValue('u_list_of_associated_cis', 'No associated CIs.');
}
}
}
script Include:-
var CIsIncident = Class.create();
CIsIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
affectedCIs: function() {
var ciList = [];
var sysID = this.getParameter('sys_parm_INCsys');
if (!sysID) {
return JSON.stringify([]);
}
var gr = new GlideRecord('task_ci');
gr.addQuery('task', sysID);
gr.query();
while (gr.next()) {
var ciDetails = {};
ciDetails.taskName = gr.task.getDisplayValue();
ciDetails.name = gr.ci_item.getDisplayValue();
ciList.push(ciDetails);
}
return JSON.stringify(ciList);
},
type: 'CIsIncident'
});
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 11:20 AM
Hi Ravi,
I wanted to bring to your attention that the script you provided earlier does not seem to be functioning as expected. I have already attempted the suggested solution, but unfortunately, it has not yielded the desired results.
Could you please explore alternative approaches or provide additional guidance to address this issue? Your assistance would be greatly appreciated.