State Flow Script not working properly

New user1212
Tera Contributor

I'm writing a script in State Flow that will allow me to go from one story state to the next.

So the point is that I wrote a script to check if there is scrum task testing in the story. If it is not there, a UI message appears that it should be added. if it is and there is no test result - pass status, a ui message is displayed that there must be a pass if it is but state is not closed complete - a ui message is displayed that it must be state closed complete. The problems are when I create scrum task testing and give state closed complete a test result fail. I get information that state must be closed complete (although it already is) and that test result must be pass. How to fix it ? the point is that the script only checks for missing data. additionally, if I create, for example, two scrum testing tasks, I want it to be possible to move to the next state flow only if at least one scrum task testing meets all three conditions.

Here is my script :

var testResultPass = false;
var stateClosedComplete = false;

var grScrumTask = new GlideRecord('rm_scrum_task');
grScrumTask.addQuery('story', current.sys_id);
grScrumTask.addQuery('type', ScrumTaskType.TESTING);
grScrumTask.query();
var haveTestingTask = grScrumTask.hasNext();

if (!haveTestingTask) {
gs.addErrorMessage(gs.getMessage("sag.agile.story.state.testing.complete.testing.scrumtask.missing"));
current.setAbortAction(true);
} else {
while (grScrumTask.next()) {

if (grScrumTask.test_result.toLowerCase() == "pass" && grScrumTask.state == ScrumTaskState.CLOSED_COMPLETE) {
testResultPass = true;
stateClosedComplete = true;
break;
}
}
if (!testResultPass) {
gs.addErrorMessage(gs.getMessage("sag.agile.story.state.testing.complete.testing.scrumtask.passed"));
}
if (!stateClosedComplete) {
gs.addErrorMessage(gs.getMessage("sag.agile.story.state.testing.complete.testing.scrumtask.complete"));
}
if (!testResultPass || !stateClosedComplete) {
current.setAbortAction(true);
}
}

action.setRedirectURL(current);

3 REPLIES 3

BharathChintala
Mega Sage

@New user1212  where did you write this script in BR or UI action?

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

w state flow - is a script that is supposed to allow you to switch from one state to another

@New user1212 

var gr = new GlideRecord("rm_scrum_task");
gr.addQuery('story', current.sys_id);
gr.addQuery('type', '4');
gr.query();
if (gr.hasNext()) {
while (gr.next()) {
if (gr.state == '3' && gr.test_result == 'Pass') { // state close completed and result pass
//add your message
} else if (gr.state == '3' && gr.test_result != 'Pass') { //state close completed and result not pass
//add your message
} else if (gr.state == '4' && gr.test_result == 'Pass') { // state close Incompleted and result pass
//add your message
} else if (gr.state == '4' && gr.test_result != 'Pass') { //state close Incompleted and result not pass
//add your message
} else {
//for all other conditions one message or you can add multiple else if conditions with state and result combination

 

Thanks

BHarath
}
}
} else {
gs.addErrorMessage("There is no Scrum task with Testing type");
}

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala