Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi - it is a before update business rule


Hi Andrew,



I thoght it worked for you.



Below piece of code is working perfectly for me. It is a before update business rule which disallows user to alert priority to 1 from 2.


Could you please send some screeshots ?



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




// Add your code here


gs.addInfoMessage("Cant alter the priority from 1");


current.setAbortAction(true);


gs.setRedirect(current);




})(current, previous);




find_real_file.png


Prateek kumar
Mega Sage

Hello Andrew



Did you had a chance to figure out this issue.?


If yes could you please let me know aswell.



-Thanks



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek - unfortunately I was required to focus on some other items so have not been able to get back to this yet.



So to answer your question - No I have not been able to get it working yet



cheers


The SN Nerd
Giga Sage
Giga Sage

This is my understanding of the requirements:


When business rule is triggered


  • Redirect the user to the record
  • Set state to previous value


So...



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


  gs.addInfoMessage("Can't alter the priority from 1");


current.setAbortAction(true);


current.state = previous.state;


gs.setRedirect(current);


  })(current, previous);



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022