Print the Incidents which are related to CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 01:10 AM
Hi All,
How to show Incident number which are related to CI Through script.
Please suggest,
Thanks,
Varma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 01:59 AM - edited 10-03-2023 02:06 AM
Hello @varma2,
Try below background script below, which gives all incident numbers belonging to a particular CI
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('name', 'Email'); // Replace Email with your required CI name
gr.query();
if (gr.next()) {
var grIncident = new GlideRecord('incident');
grIncident.addQuery('cmdb_ci', gr.sys_id);
grIncident.query();
while (grIncident.next()) {
gs.info(grIncident.number);
}
}
Find the background script below, which gives all incident numbers belonging to all CIs.
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
var grCI = new GlideRecord('cmdb_ci');
if (grCI.get(gr.cmdb_ci)) {
gs.print('Incident Number: ' + gr.number + ', CI Name: ' + grCI.name);
}
}
Please mark my answer correct & helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 02:59 AM
Hi @varma2 ,
Why through a script? why not just create a report "if that is what is needed" based on the configuration item?
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/