- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 11:00 AM
Hi
Using background script i need to fetch the no of incident in all categories for active incidents only.
Can someone help me here?
I am able to fetch the no of incident records.
How can i fetch the no of record for each category in BACKGROUND Script ONLY.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 12:12 PM
Hi,
Try this
var incidents = new GlideRecord('incident');
incidents.addEncodedQuery('active=true^subcategory!=');
incidents.query();
while (incidents.next()) {
var category = incidents.category;
var subcategory = incidents.subcategory;
gs.print('cat' +category);
gs.print('sub' +subcategory);
if(category=='inquiry' && subcategory=='antivirus')
{
gs.print('sssss');
incidents.subcategory='software';
incidents.subcategory='email';
incidents.setWorkflow(false);
incidents.update();
}
}
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 12:08 PM
No luck with this also

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 12:12 PM
Hi,
Try this
var incidents = new GlideRecord('incident');
incidents.addEncodedQuery('active=true^subcategory!=');
incidents.query();
while (incidents.next()) {
var category = incidents.category;
var subcategory = incidents.subcategory;
gs.print('cat' +category);
gs.print('sub' +subcategory);
if(category=='inquiry' && subcategory=='antivirus')
{
gs.print('sssss');
incidents.subcategory='software';
incidents.subcategory='email';
incidents.setWorkflow(false);
incidents.update();
}
}
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 12:27 PM
Worked!
Can you tell me why we used
incidents.setWorkflow(false);
?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2021 12:36 PM
Hi
Glad that it worked.
We used to this to make sure when we update record no other Business rules which runs on update for same table will run. This way you can stop unnecessary emails on update then unnecessary BR trigger.
Its best practice if you dont want anything else to happen when you run script from background or fix script.
If you feel its not needed you can remove it and it will still work
Hope this helps 🙂
Please don't forget to mark my answer correct and helpful:)
Thank you and stay safe
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2024 07:33 AM
Hi I need to display the incident numbers as well, could anyone help?? Like if software category has 4 incidents under it I have to display it like
Category software count 4
INC0001
INC0002
INC0003
INC0004