Business Rule to Update Story State to Complete when all Scrum Tasks are Complete

Cody17
Tera Contributor

Hello,

 

I am trying to write a business rule to update a story's state to complete when all the scrum tasks are in a state of complete or cancelled, but I am struggling to get it to work.  I was hoping someone might be able to help me with my script.  It is currently targeting the rm_scrum_task table, after update, and when the state changes.  

 

(function executeRule(current, previous /*null when async*/ ) {

var gr = new GlideRecord('rm_scrum_task');

gr.addQuery('parent', current.parent);
gr.addQuery('state', '3');
gr.addQuery('state', '4');
gr.query();

while (gr.next()) {
if (gr.state == '3' || gr.state == '4') {
gr.parent.state == '3';
}

}


})(current, previous);

1 ACCEPTED SOLUTION

Sorry there was a typo in my code. Can you try again?

(function executeRule(current, previous /*null when async*/ ) {

    var gr = new GlideRecord('rm_scrum_task');
    gr.addQuery('parent', current.parent);
    gr.addActiveQuery();
    gr.query();
    if (!gr.next()) {
        var par = current.parent.getRefRecord();
        if (par.isValidRecord()) {
            par.state = '3';
            par.update();
        }
    }


})(current, previous);

 

View solution in original post

8 REPLIES 8

Mike_R
Kilo Patron
Kilo Patron

Try this 

 

(function executeRule(current, previous /*null when async*/ ) {

    var gr = new GlideRecord('rm_scrum_task');
    gr.addQuery('parent', current.parent);
    gr.addActiveQuery();
    gr.query();
    if (!gr.next()) {
        var par = current.parent.getRefRecord();
        if (par.isValidRecord()) {
            par.state = '3';
            par.update();
        }
    }


})(current, previous);

 

Cody17
Tera Contributor

I tried that but when I updated the scrum task to complete the parent story was still work in progress.

Can you post a screenshot of your "When to run" tab of your business rule?

Cody17
Tera Contributor

099921f5f0a1903be270b9ab13431161.png