Redirect to current after submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2015 04:21 PM
I'm currently working on a custom application built from the bottom up and having quite a deal of trouble simply trying to redirect to the record that was just created by the user (on the custom table). Currently there is 1 update business rule and 1 insert business rule (both before) that have the same line of code that works for the user:
action.setRedirectURL(current);
The problem is the records get updated each day by a scheduled job and when the business rule runs when the record is updated action is not defined:
org.mozilla.javascript.EcmaError: "action" is not defined.
Caused by error in Business Rule: 'Foo Foo - Update' at line 4
This "warning" error actually halts my business rule from continuing.
I've tried:
if(action) { action.setRedirectURL(current); }
if(!gs.nil(action)) { action.setRedirectURL(current); }
if(typeof action != 'undefined') { action.setRedirectURL(current); }
if(typeof action != undefined) { action.setRedirectURL(current); }
gs.setRedirect(current.getLink());
gs.setRedirect(current.getLink(true));
gs.setReturn(current.getLink());
gs.setReturn(current.getLink(true));
All I want to do is get the user back to the record they had just created, and have my scheduled job not throw an error every day when it runs.
P.S. Turning business rules or updates off during this transaction is not an option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 09:06 AM
You may want to look at the code at the end of the Save UI action. Because when you press save on a form it stays on the same page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 08:44 PM
When the business rules run on these from a background script or a scheduled job they fail hard because of that line of code, and with all those different methods that I've tried, I've resorted to use this in my business rule.
try { action.setRedirectURL(current); }
catch(e) {}
which is expensive, but its the only thing that doesn't hault my processing AND gets the user back on the same record when submitting (insert).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 01:00 AM
action does not exist from the context of a Background Script.
action only exists in business rules triggered by a UI action or the server side UI action.
You can't redirect a user to a new page via a scheduled script, it simply isn't possible.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 10:42 PM
I know it's a bit old, but you may have some luck with gs.isInteractive()