window.open written in a client script and its not working on Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 04:36 AM
Hi Folks,
I have a catalog item and in that there is onchange client script which opens different URLs based on the value selected using window.open() function.
But this script is not working on Service Portal. I have changed the UI type of the script to "Both" as well.
Please help.
Thanks
Preety Arora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 11:03 AM
In Angular you have to use the "$window" service instead of just "window":
function($window) {
$window.open('http://google.com');
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 09:40 PM
if window is not supported in SP then what can be the alternative approach for below script (which is currently being used)
if(g_form.getValue('issue_name') == "Restore issue")
{
alert(window); // this is returning null
top.window.location.href = "xxxxxxx"; // this is working but opening in same page.
window.open("xxxxx"); // not working
}
I tried $window as well . But not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2016 01:53 AM
The code below worked for me in the Service Portal in Helsinki patch6-hotfix1.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Redirect if the answer is no
var variableName = g_form.getValue('variable_name');
if (variableName == 'No'){
var win = top.window.open('http://www.google.com', '_blank');
if(win){
//Browser has allowed it to be opened
alert('You are being redirected to another site.');
win.focus();
}else{
//Broswer has blocked it
alert('Please allow popups for this site.');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 08:36 PM
Note: the 'top' and 'self' objects can be used in client scripts in scoped apps.
- top refers to the top-most/parent window
- self refers to the window/iframe (gsft_main) that contains the detailed view - e.g. the incident form.
Example:
top.location.href - will return https://instance.service-now.com/nav_to.do?uri=/incident.do%3Fsys_id%3Dd45e4534dccb7400cac937e91440d...
self.location.href - will return https://instance.service-now.com/incident.do?sys_id=d45e4534dccb7400cac937e91440d158