The CreatorCon Call for Content is officially open! Get started here.

I need to close incident when incident task is closed.

niveditakumari
Mega Sage

Hi, 

 

I need to close incident when incident task is closed. Which approach should we use before and after business rule and how to achieve that. 

Can anyone please help me with that. 

 

Regards, 

Nivedita 

 

 

1 ACCEPTED SOLUTION

Hi @niveditakumari 

 

I am not a pro or coder , but my experience with technical team says, here, go with After BR.

*************************************************************************************************************
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]

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

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @niveditakumari 

https://www.servicenow.com/community/itsm-forum/auto-close-incident-when-incident-tasks-are-closed/m...

 

*************************************************************************************************************
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]

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

Hi @Dr Atul G- LNG

 

I'm more focusing on which approach would be better Before or After business. I have written for same on request and task table. 

Can you please confirm in that type of use case which approach we should use Before or After business rule. 

 

Regards, 

Nivedita 

 

 

Hi @niveditakumari 

 

I am not a pro or coder , but my experience with technical team says, here, go with After BR.

*************************************************************************************************************
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]

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

Hi @niveditakumari 

You can go with 'after' business rule and try checking if your issue is resolved.
Else , use this code

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


}
Hope it helps.

Regards,
Kiranmai.


})(current, previous);