Redirect in Business Rule (scoped vs not)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:13 AM
I am working in a scoped app, not sure if that makes any difference.
Trying to use a display BR to check values on load, if they exist then return the user to the previous form with an error message.
However, following all docs and posts out there using gs.setRedirect(url) doesn't seem to work.
current code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:54 AM
I think Instead of directly concatenating the URL, use the GlideURL object to construct the URL. This ensures that the URL is properly formatted and respects scoped app constraints.
var url = new GlideURL('<table_name>.do');
url.addParam('sys_id', '<previous sys_id>');
gs.addInfoMessage('Redirecting...');
action.setRedirectURL(url);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 08:37 AM
I am receiving the following Error Message now
GlideURL is not allowed in scoped applications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:50 PM
If GlideURL is not allowed in scoped applications, you can try using URI instead to construct URLs.
// Construct the URI object with the base URL
var uri = new URI('<table_name>.do');
// Add the sys_id parameter to the URI
uri.addQuery('sys_id', '<previous_sys_id>');
// Display an info message
gs.addInfoMessage('Redirecting...');
// Set the redirect URL using action.setRedirectURL()
action.setRedirectURL(uri.toString());
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 08:52 PM
HI @Wade Clairmont ,
I trust you are doing great.
In a scoped ServiceNow application, you can't directly use GlideURL to construct URLs. Instead, you can use the URI object. Here's how you can modify your code:
// Construct the URI object with the base URL
var uri = new URI('<table_name>.do');
// Add the sys_id parameter to the URI
uri.addQuery('sys_id', '<previous_sys_id>');
// Display an info message
gs.addInfoMessage('Redirecting...');
// Set the redirect URL using action.setRedirectURL()
action.setRedirectURL(uri.toString());
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi