Using background script i need to fetch the no of incident in all categories for active incidents only.

Deepali Rattan
Tera Contributor

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

1 ACCEPTED SOLUTION

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

View solution in original post

9 REPLIES 9

@Prasad Pagar 
No luck with this also

 

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

Worked!
Can you tell me why we used 

incidents.setWorkflow(false);

?

Hi @Deepali Rattan 

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

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