- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 12:57 AM
Hi
I would like to create a rule that if an Incident has any Open (Incident) Tasks the Incident cannot be closed.
Not all Incidents will have tasks.
Any help?
Thanks
Riaz
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 03:03 AM
Hi Riaz,
Please add filter condition in BR as below:
and in code do the gliding on incident_task table rather then incident as below and then try:
Thanks,
Anjali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 01:17 AM
Hi Riaz,
Create a Business Rule on incident table.
to implement this.
I think it will help you If you are looking for some code let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 01:21 AM
Hi Sanjeev,
Thanks - Yes some code would be good please. I assume maybe a generic piece of code.
Thanks
Riaz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 02:19 AM
Hi Riaz,
Check with the below code once
Table:Incident
business rule type: before update
Filter condition : State changes to closed
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.state=="3"){ //here 3 is the value of closed state
var inctask=new GlideRecord('incident_task');
inctask.addQuery('parent',current.sys_id);
inctask.query();
while(inctask.next()){
if(inctask.state!="3"){//here 3 is the value of closed state
gs.addErrorMessage("Incident task is not closed");
current.setAbortAction(true);
}
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2017 02:09 AM
Hi Riaz,
You can try creating a Business Rule as below:
Name: Prevent Closure if Child Task is Active
Type: "Before Update" Business Rule
Table: Incident
Description: Prevents closing a task if any of the task's child tasks are still active.
Script:
var gr = new GlideRecord('incident');
gr.addQuery('active','true');
gr.addQuery('parent',current.sys_id);
gr.query();
while (gr.next())
{
current.setAbortAction(true);
}
If the reply was informational, please like, mark as helpful or mark as correct!!
Thanks,
Anjali