Auto create incident task when incident state is resolved

prasad8
Giga Expert

Hi 

I have a requirement :

I need to Auto create incident task when the Major incident feild is Checked and  incident state is changed to resolved.

For this i have created one business rule 

conditions : AFTER - Update 

Major incident is true

state changes to resolved 

Script:

var incTask = new GlideRecord('incident_task');
incTask.initialize();
incTask.short_description = current.short_description; 
incTask.incident = current.sys_id;
incTask.insert();

 

Here the issue i am facing, If the incident is moved to resolved state incident task is created, But if the same incident state is back to inprogress and after that again it moves resolved state it creating another incident task for same incident.

As per my requirement, I need incident task first time state moves to resolved 

Please help me on this 

 

 

1 ACCEPTED SOLUTION

Sulabh Garg
Mega Sage
Mega Sage

Hello

In this case, you can have one condition to check whether "Incident_task" is already created or not for specific Incident only then create new incident_task, else it should not create new incident_task.

Write the below script in BR as you mentioned

var grIT = new GlideRecord('incident_task');
grIT.addEncodedQuery("incident="+current.sys_id);
grIT.query();
if(!grIT.next()) {  //If there is no Incident task created on Incident then go inside If

//Execute your Insertion code as you mentioned..

}

Please Mark Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

View solution in original post

5 REPLIES 5

Sanjay Bagri1
Tera Guru

Hi 

Please try below code: 

var incTask = new GlideRecord('incident_task');
incTask.addQuery('sys_id',current.sys_id);
incTask.query();
if(incTask.next()==0){
incTask.initialize();
incTask.short_description = current.short_description; 
incTask.incident = current.sys_id;
incTask.insert();
}else
{
 g_form.addErrorMessage(incTask.number +" This incident Task is already exist");
}

 

Please mark my answer Correct/helpful,

Regards

Sanjay Bagri