gs.setRedirect() in combination with current.setAbortAction(true) not executed (Before/Update BusinessRule)

Meloper
Kilo Sage

Hi,

if a Problem has an active ProblemTask or an active attached Incident, it should not been closed.

I use an on before BR.

current.setAbortAction works but the Form does not reload.

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

    //Check for active Problem Tasks of Current Problem
    var grPTASK = new GlideRecord("problem_task");
    grPTASK.addQuery("problem", current.sys_id);
    grPTASK.addQuery("active", true);
    grPTASK.query();
    if (grPTASK.hasNext()) {

        current.setAbortAction(true);
        gs.addErrorMessage('Anzahl der Problems gleich' + grPTASK.getRowCount());
        gs.addErrorMessage('Anzahl der current state gleich' + current.state.getDisplayValue());
        gs.addErrorMessage('Anzahl der previous state gleich' + previous.state.getDisplayValue());

        current.state = previous.state;
        gs.setRedirectURL(current);

    } else {
        var grINC = new GlideRecord("incident");
        grINC.addQuery("problem_id", current.sys_id);
        grINC.addQuery("active", true);
        grINC.query();
        if (grINC.hasNext()) {

            current.setAbortAction(true);
            gs.addErrorMessage('Anzahl der Incidents gleich' + grINC.getRowCount());

            current.state = previous.state;
            gs.setRedirectURL(current);
        }
    }



gs.setRedirectURL(current);
})(current, previous);

 

I found many unsolved Question and this KB/Problem:

https://hi.service-now.com/kb_view.do?sysparm_article=KB0539962

We also use some BR with this commands and it works....

 

So i need a refresh of the Form after the action aborted.

What should i do?

 

Currently it behaves like this:
The Action aborted and the new Values are on the form. User has to refresh and the Record appears with the previous Values. 

 

But i don#t want that the user has do refresh manually.

 

11 REPLIES 11

Hay it does not work with

action.setRedirectURL(current); 

gs.setRedirectURL(current); 

or

action.setRedirect(current); 

gs.setRedirect(current); 

Hi,

action object doesn't work in business rules

Regards
Ankur

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

Meloper
Kilo Sage

Answer from HI Portal

Most Probable Cause: Working as designed Solution Proposed: I tried calling you on the number mentioned in the Case but could not connect. There is a known problem for this issue - PRB604580 in the platform, and our dev team investigated and set the state as 'won't fix' with the following reason. The behavior of gs.setRedirect() being disregarded when the action is aborted is by design. The real issue here is that using multiple tabs against the same instance can produce unexpected results, which has unfortunately always been the case. Multiple tabs use the same navigation stack. You'll get similar behavior if you have two tabs open, navigate around a bit in each, then try to use the green "back" button. Unfortunately, as of now this is a product limitation by design and there is no workaround. The above comment also explains the inconsistencies, enabling this feature can cause.

adding one thread here, @paul has mentioned one workaround, see if  it helps you. 

 

https://community.servicenow.com/community?id=community_question&sys_id=8ecf32addb58dbc01dcaf3231f96...

Hay, Thanks, but it does not work. Pleas look at my Script. I use the same Code