stories cannot be moved

jean-pauldehaas
Tera Guru

Hi,

 

i have this requirement: storiescannot be moved from Ready for testing into Testing or Complete state if a Code Review Task(scrumtask) is still open.

 

i created this script besides the fact that i need to check for the correct state values, can annyone tell me if this script should work:

 

(function executeRule(current, previous /*, gdt, validationResult*/) {

    // Check if the current story is in "Ready for testing" state
    if (current.rm_story === "story" && current.state === -7) { // Replace "3" with the appropriate state value for "Ready for testing" in your instance

        // Query for any open "Code Review" tasks related to this story
        var codeReviewTask = new GlideRecord("rm_scrum_task");
        codeReviewTask.addQuery("parent", current.sys_id); // Assuming the "Code Review" task is related to the user story through the "parent" field
        codeReviewTask.addQuery("state""!="3); // Replace "3" with the appropriate state value for "Closed" in your instance
        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, previous);
4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

"can annyone tell me if this script should work"

You can test that right. What is your real question, what is the issue you are really facing? Or is it like you copied the script and have limited scripting knowledge and asking therefor?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

mark,

 

you are completly right, im trying to learn and get better.

Mark Roethof
Tera Patron
Tera Patron

Just looking at the script, already this looks odd to me:

current.rm_story === "story"

 

Can you verify the rm_story field. Is that indeed on your table and if so what type is it. I wouldn't expect to see such a field here or at least not as a string value.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Looking at:

if (current.rm_story === "story" && current.state === -7) {

 

Can that also be moved to the condition field of the business rule? Using the Filter Conditions or Condition is a best practice, and when using the Filter Conditions you also don't need any scripting knowledge.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn