- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:18 PM
I have a requirement to get the "Affected CI's"(task_ci) list attached to the incident in a client template.By using the below script,I am getting the list of Affceted CI's.But to the last value the comma is getting concatenated.I tried to remove in many ways as shown in the script below(commented),but the last operator(highlighted in Red) is not getting remove.
Below is the mail script I used and Result I am getting:
Result:
Service Impacted: CDN_ITS_AlfrescoRetrievePropertiesService_PROD,AWD - FORMS, DocGenDashboard (Member statements)- SL - UAT, GIS Messaging - Production - CA, IGP Captive Reporting - INST - SIT,
Email Script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var gr1=new GlideRecord('task_ci');
var a="";
gr1.addQuery('task',current.incident_alert.source_incident.sys_id);
gr1.query();
while(gr1.next()){
//gs.print(gr1.name.getDisplayValue());
//template.print(gr1.ci_item.getDisplayValue() + "<br/>");
a=gr1.ci_item.getDisplayValue() + ",";
// a=a.substr(0, a.length-1);
// var lch = a.slice(-1);
// if(lch == ','){
// a=a.slice(0,-1);
// }
//var newa = a.length-1;
//a=newa.replace(",","");
// template.print(newa.replace(/.$/,""));
template.print(a);
}
/*function removeLastComma(strng){
var n=strng.lastIndexOf(",");
var a=strng.substring(0,n);
return a;
}*/
})(current, template, email, email_action, event);
Thanks in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:33 PM
Hi Kumar,
can you try using an array instead?
script below
var arr = [];
var gr1=new GlideRecord('task_ci');
gr1.addQuery('task',current.incident_alert.source_incident.sys_id);
gr1.query();
while(gr1.next()){
var value = gr1.ci_item.getDisplayValue();
arr.push(value.toString())
}
template.print(arr);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:21 PM
Hi there,
Have you considered using a array? This way you don't have to deal with a trailing seperator. Dig in to things like .push / .join:
var list = [];
list.push(gr1.ci_item.getDisplayValue());
list.join();
(the push would be done in your while)
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:33 PM
Hi Kumar,
can you try using an array instead?
script below
var arr = [];
var gr1=new GlideRecord('task_ci');
gr1.addQuery('task',current.incident_alert.source_incident.sys_id);
gr1.query();
while(gr1.next()){
var value = gr1.ci_item.getDisplayValue();
arr.push(value.toString())
}
template.print(arr);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:39 PM
Using an array and join would definetely help you to reduce the redundant script
Thanks,
Siva
Mark this response as correct if that really helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 04:55 AM
Thanks All for the help.By using the Array it worked.