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

Ankur Bawiskar
Tera Patron
Tera Patron

@jean-pauldehaas 

Check response shared by Aman and share us the updates.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

maxwel
Kilo Contributor

There are a few reasons why state might not be saved in a React application. Here are some of the most common ones:

The setState() method was not called. This is the most common reason why state is not saved. The setState() method is used to update the state of a component. If the method is not called, the state will not be updated.

The setState() method was called with an invalid argument. The setState() method takes an object as an argument. The object must contain the key-value pairs that you want to update. If the object is invalid, the state will not be updated.

The setState() method was called too often. The setState() method can be called multiple times, but it is important to call it at a reasonable rate. If the method is called too often, the state may not be saved.

The setState() method was called from a component that is not mounted. A component is mounted when it is first rendered. If the setState() method is called from a component that is not mounted, the state will not be saved.