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

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Taking a step back, I want to understand what good a task do when incident is already marked resolved?

Who will look at this task and what will happen to it? how will it get closed?

When will incident be marked as closed?

 

Can you explain what you are trying to do?

 

-Anurag

 

-Anurag

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

Hi @Sulabh Garg ,

 

It is working as expected.

Thankyou.

 

I am glad it resolved the issue 🙂

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