- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 12:28 PM
I have requirement when a user click on a module, user should be directed to a URL based on his/her role. I am using a link type Script (from Argument) for a module to run a script to dynamically generate a URL based on user's role.
How do I redirect to the URL from the script automatically?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2022 12:08 AM
Hi
Please go through the below post where similar query has been answered.
https://community.servicenow.com/community?id=community_question&sys_id=1c0c4725db9cdbc01dcaf3231f9619fc
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 02:45 PM
It seems you can place a piece of JavaScript into the Arguments field if it starts with the keyword javascript:
. What follows would be a client side JavaScript.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2022 08:10 AM
Thanks Janos. I have used script and created the function to build the URL. I am calling this function using Script (from Arguments), but challenge is how to automatically redirect to the generated URL to open a page.
I also tried creating a UI Page, tried calling the same function using <g:evaluate which is returning correct URL, but not I want to redirect to URL to open the page. Is there any way to pass the variable to processor script?
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_error_message" object="true" jelly="true">
var v_url=getRoleHomepage();
gs.addInfoMessage(v_url);
</g:evaluate>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2022 12:14 PM
I'm sorry - I just now realize - I have answered beside the point: was thinking of "URL (from Arguments:)" not "Script (from Arguments:)".
Modules of type "Script (from Arguments:)" basically execute the script as if executed in Scripts - Background. And I have no idea how one could redirect the output of Scripts - Background. So I don't think you should be using that. Those seem to have been created to execute something on server side when clicked and that's it.
As for redirecting, that is a function of a HTTP server. It happens in a layer encompassing UI Pages, or any pages in fact. That layer is not easily and for sure not everywhere accessible, it can be done in Scripted REST API for instance. Or in Processors, but that is no longer officially supported.
g_navigation.open()
. Thus when someone clicks on the module or the g_navigation
API is executed, the REST API end-point would execute and would redirect as you defined it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2022 04:04 PM
Thanks, Janos.
I was able accomplish it within the UI Page. Using the variable, value that was set within <g2: evaluate >, in the client script in the UI Page to redirect using document.location.href .