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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @shash gauti 

 

You can give a try with Flow Designer. 

 

Look Up records with condition.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Shoheb_IbaaBoss
Tera Guru

Hi,

Please try below approach:

 

BR - RemoveIncidentFromOnHold

Condition:

Active is true

incident.state is 'On Hold

incident_task.state is not 'On Hold'

 

Script:

(function executeRule(current, previous /*null when async*/) {
var incidentGR = new GlideRecord('incident');
if (incidentGR.get(current.incident)) {
var onHoldTasks = new GlideRecord('incident_task');
onHoldTasks.addQuery('incident', incidentGR.sys_id);
onHoldTasks.addQuery('state', 'On Hold');
onHoldTasks.query();

// If no other incident tasks are on hold, update the incident state
if (!onHoldTasks.hasNext()) {
incidentGR.state = 'In Progress'; // Set the desired state when not on hold
incidentGR.update();
}
}
})(current, previous);

 

Regards,

Shoheb

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

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