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

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);

 

Cody17
Tera Contributor

That worked, thank you for the help Mike!

Hello Mike, how would I do this when the scrum tasks are set to cancelled. How would I change the parent state to cancelled? This is the code I have so far: 

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

    var gr = new GlideRecord('sn_safe_scrum_task');
    gr.addQuery('parent', current.parent);
    gr.addActiveQuery();
    gr.addQuery('state', '!=', '4');
    gr.query();

    if (!gr.next()) {
        var par = current.parent.getRefRecord();
        if (par.isValidRecord()) {
            par.state = '4';
            par.update();
        }
    }

})(current, previous);

The code you sent for the original worked perfectly. But when I run the code for the cancelled state, it is setting the parent to complete?