Script to change the Incident state from Onhold to progress

shash gauti
Tera Contributor

Hi All

 

Whenever an incident task is removed from on hold then the incident also should be removed from on hold only If no other incident tasks under that incident is already on hold awaiting caller.

 

Can anyone help ?

 

Thanks

2 ACCEPTED SOLUTIONS

piyushsain
Tera Guru
Tera Guru

Hi @shash gauti 

You have to create a After Update BR on table incident_task with condition state changes from on-hold

var incTask = new GlideRecord('incident_task');
incTask.addQuery('incident',current.incident);
incTask.addQuery('state',,'on-hold');//if on-hold value is different add the correct value
incTask.query();
if(!incTask.next()){
var incident = new GlideRecord('incident');
incident.get(current.incident);

incident.state = 'add your value';
incident.update();

}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

Musab Rasheed
Tera Sage
Tera Sage

Try below.

Create after BR on incident task table.

(function executeRule(current, previous /*null when async*/) {
var count=0;
var tasks = new GlideRecord('incident_task');
tasks.addQuery('incident',current.incident);
tasks.query();
var taskcount = tasks.getRowCount();
while(tasks.next())
{		
if(tasks.state != 'onhold')//change as required
{
count++;
}
}
if(count == taskcount)
{
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',current.incident);
inc.query();
if(inc.next())
{
inc.state = 'add state value';
	inc.update();
	}

}

})(current, previous);

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@shash gauti 

what did you start with?

where are you stuck?

Unless you start and debug you won't learn.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader