state is not saved

jean-pauldehaas
Tera Guru

Hi,

 

im trying to prevent the state from moving to Testing or Complete if a scrum task is still open.

i created this script, its displaying the message so thats work but it doesnt keep it in the Ready for testing (-7) state when you refresh the page.

 

(function executeRule(current, previous ) {

        // Query for any open "Code Review" tasks related to this story
        var codeReviewTask = new GlideRecord("rm_scrum_task");
        codeReviewTask.addQuery("parent", current.sys_id);
        codeReviewTask.addQuery("state""!="3);
        codeReviewTask.query();

        // If there is an open "Code Review" task, prevent the state change
        if (codeReviewTask.hasNext()) {
            gs.addErrorMessage("Cannot move the story to 'Testing' or 'Complete' state. There is an open 'Code Review' task.");
            current.setAbortAction(true);
            current.state = -7;
            current.setWorkflow(false);
        }
    }

)(current, previous);

 

 

what am i missing?

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @jean-pauldehaas ,

Hope you are using Before Update BR.

And condition should be State changes to Complete OR Testing.

You do not need to explicitly set the state as -7, setAbortAction will be sufficient here. No need of setWorkflow as well.

Best Regards
Aman Kumar

View solution in original post

6 REPLIES 6

Aman Kumar S
Kilo Patron

Hi @jean-pauldehaas ,

Hope you are using Before Update BR.

And condition should be State changes to Complete OR Testing.

You do not need to explicitly set the state as -7, setAbortAction will be sufficient here. No need of setWorkflow as well.

Best Regards
Aman Kumar

Hi Aman,

 

your solution works perfect but i have an additional requirement.

if there is no task created yet it should not be possible to move the state to Testing state, how can i add this to the current script ?

 

*the first task gets created from the ready for testing state so it should not be possible to move a story from draft/ready/work in progress

 

I would suggest instead of adding more logic to it, why don't you restrict users to be able to move from Draft/Ready/WIP to closed.

In the same BR, just check with an overall if condition, something like

if(current.state.changesFrom(<state of ready>) || current.state.changesFrom(<state of WIP>) ||current.state.changesFrom(<state of Draft>) ){

gs.addErrorMessage("Cannot move the story to 'Testing' or 'Complete' state from Draft/Ready/WIP");
            current.setAbortAction(true);

}

 

 

 

Best Regards
Aman Kumar

hi Aman,

 

i got it fixed by adding an Else condition into my exisiting script, this resolves my requirement.

 

thanks!