- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 02:25 PM
I have a record producer that creates a parent enhancement task and auto creates 5 child general task. I would like to prevent from 'Closed Complete' the parent task until all the child general task are 'Closed Complete'.
Can someone please help with this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 02:49 PM
You would need a BR something like below:
and your script will look similar to below:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('pass child table name');
gr.addQuery('parent', current.sys_id);
gr.addQuery('state', '!=', 3);
gr.query();
while(gr.next()){
gs.addErrorMessage('Cannot close Parent with open child');
current.setAbortAction(true); //abort the record
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 06:39 AM
Thanks @Prateek kumar this script was perfect for us. For the Business Rule itself, on the When to run tab we also limited it to only apply for Update (not inserts) and added a filter condition so that it will only run when the State changes to Closed. And for the gr.addQuery script step, for our use case checking for Active=true was more appropriate than a specific change task state, because we are OK if tasks were marked as State=Canceled too, for us they don't all have to end up with State=Closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 03:01 PM
Hi ,
Please try below script in before update business rule on parent table:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('your task table '); // This will be the child task table
gr.addQuery('parent',current.sys_id); ///field on the child table where the parent record number
gr.addActiveQuery();/Only want to look if there is active tasks
gr.query();
if(gr.next()){
gs.addErrorMessage('please close all related child tasks');
current.setAbortAction(true);
}
})(current, previous);
Please mark it as helpful (or) correct if it helps.
Thanks,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 03:05 PM
Assuming your enhancement records are part of rm_enhancement table and the your 5 created tasks are part of rm_scrum_task.
Then the records in rm_scru_task will have a field populated as:
<parent display_value="ENHC0010003">34b88b8f0f7b9a80ca182ca8b1050e11</parent>
The Business Rules executing on table "rm_enhancement" could have something like this (evaluated on before update):
******************
Condtion: current.state.changes() && current.state=='3'
Script:
(function executeRule(current, previous /*null when async*/) {
var checkMe = new GlideAggregate("rm_scrum_task");
//checking if there are still child tasks not closed complete..
checkMe.addEncondedQuery("parent="+current.sys_id+"^state!=3");
checkMe.addAggregate("COUNT");
checkMe.query()
var answer = true;
if(checkMe.next()){
// this means that we found existing child records not closed completed....
answer=false;
}
//posting a message..
if (answer=true){gs.addErrorMessage('Unable close complete the Enhancement with an open child task, please verify.');
}
current.setAbortAction(answer);
})(current, previous);
*******************
Hope this helps,...