Redirect URL related List in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 05:56 AM
Hi ,
Need help with adding URL page in related list using action.setRedirectURL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 09:53 AM
Hi Bhavani,
I'm unable to figure out what you are trying to accomplish. Can you elaborate?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2015 02:44 AM
Hi,
I need to build an UI action (ie: related links)
In my custom app
To redirect to a create new form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2015 10:01 AM
Hi Bhavani,
OK, you want someone to click on one of the related links, and when they do so, be taken to another page. That is common in the platform.
In your UI Action script, you will want to use action.setRedirectURL. See this example from the out-of-box Take Survey UI Action:
var url = 'survey_take.do?sysparm_survey=' + surveyName + '&sysparm_task_survey=' + current.sys_id;
action.setRedirectURL(url);
When they click that link, should the form they are on currently be submitted (saved)? If so, you'll first want to do a current.update. Again, see the Take Survey example:
current.update();
var surveyName = GlideStringUtil.urlEncode(current.survey.name)+'';
var url = 'survey_take.do?sysparm_survey=' + surveyName + '&sysparm_task_survey=' + current.sys_id;
action.setRedirectURL(url);
If you want to send them to a specific record in your redirect, you'll want to get the GlideRecord object for that particular record, and redirect to that. The out-of-box View Original Event UI Action does this:
redirectToOriginalEvent();
function redirectToOriginalEvent() {
var originalID = current.getValue("parm1").substring(11);
var table = current.getTableName();
var event = new GlideRecord(table);
if (!event.get("sys_id", originalID)) {
gs.addErrorMessage("Event record not found.");
action.setRedirectURL(current);
return;
}
action.setRedirectURL(event);
}
On the other hand, if you don't want to redirect after a submit, or you want to send the user entirely out of the platform, then a client-side solution is what you need. If you want to open a new window (the most common request) the UI Action needs to be marked "Client", and have an onclick function.
onclick: openMyWindow();
function openMyWindow() {
var myUrl = "https://community.servicenow.com/";
window.open(myUrl, "_blank");
}
If you want to open it in same pane that the current form is in, you need to target that frame. Generally, this is "gsft_main", but that may not always be the case.
onclick: openMyWindow();
function openMyWindow() {
var myUrl = "https://community.servicenow.com/";
window.open(myUrl, "gsft_main");
}
Another problem with targeting a frame to load an external URL is that the external site may set an HTTP header (X-Frame-Options: SAMEORIGIN) that prevents loading the page in a third-party iframe.
There are plenty of examples withint he out-of-box system for all sorts of UI Actions and redirects. I strongly recommend reading through the existing actions, or finding one that does something similar to what you want to accomplish, checking out how it works, and then implementing it for your needs.
Thanks
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2015 10:56 AM
Oops, I left out the specific case you mentioned (going to a new record). Here is an example of that, from the "Create Transform Map" UI Action:
action.setRedirectURL("sys_transform_map.do?sys_id=-1&sysparm_query=source_table=" + current.name);
Here all it is doing is setting the redirect (where to go after the current form is submitted) to the sys_transform_map table's new record form, and automatically pre-populating the "source_table" field to contain the name of the Web Service that the user was looking at when they clicked the link.