Reload form after abort action

andrewdunn
Giga Expert

Team - I have been reading the forums and trying to get a business rule to reload a form.

What I am attempting to do is;

  • take the code from "Prevent Closure if Child Task is Active"
  • if a user goes to close the problem and a problen task is still open they see the 2nd screen shot below
  • As you can see the 2nd screen shot actually appears as if the ticket has closed
  • What I am looking to achieve is a combination of the second screen shot (shows the error) combined with the ticket showing that it is still open.

My code in the before business rule is:

var gr = new GlideRecord('problem_task');

gr.addQuery('active','true');

gr.addQuery('problem',current.sys_id);

gr.query();

if (gr.next()) {

gs.addInfoMessage('Problem cannot be closed while problem tasks are still active.');        

current.setAbortAction(true);

}

I assume it will be a couple of lines of code to redirect/reload the form but have been unsuccessdul so far - any thoughts?

So that the initial screen shot of the problem ticket is:

Image01.png

If the business rule kicks in

Image02.png

And if I reload the ticket through the UI action

Image03.png

14 REPLIES 14

Deepak Ingale1
Mega Sage

Hi Andrew,



You need to put below line inside IF loop , that should reload the form for you.



                            gs.setRedirect(current);


Hi Deepak - thanks for the response.


I tried the code both before and after the setAbort line of code in the IF statement


Still getting the same results


Cheers


hi Andrew,



Great, if it worked for you, could you please mark response as 'correct / helpful' and close the thread ?


Kindly let me know if you have any follow up questions.


Hi Andrew,



Can you please if your Business Rule is Before Update not on After Insert/update. That might help.



Scripting in Business Rules - ServiceNow Wiki