- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 08:20 AM
Hey everyone,
I'm trying to open an image with a button click using UI action (server-side script).
there is a way to redirect to a new window/tab?
Most of the solutions I found refer to the client-side.
this is my script: (the script work ok, but the image open in the same page)
var UrlImageSysId='';//image sysId for url param
var url='';//url for redirect
var currentImage = current.sys_id;//current image sysId from 'u_ts_image' table
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',currentImage);
gr.query();
if(gr.next()){
UrlImageSysId=gr.sys_id;
}
url = 'https://hpindigodev.service-now.com/'+UrlImageSysId+'.iix';
action.setRedirectURL(url);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 06:15 AM
It is not possible to open a new tab or window in a browser by server-side code alone. You can only choose the next page shown.
When you think about it - the server cannot control the browser on a client's computer. If it could, that would be a massive security flaw!
You need to do it with both Client and Server Scripts.
This is how:
- Write a Client callable Script include called AttachmentAjaxUtil with your attachment fetch script that takes currentImage as a parameter and returns UrlImageSysId
var AttachmentAjaxUtil = Class.create(); AttachmentAjaxUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, { getAttachmentSysId: function() { var UrlImageSysId='';//image sysId for url param var url='';//url for redirect var currentImage = this.getParameter('sysparm_currentImage');//current image sysId from 'u_ts_image' table var gr = new GlideRecord('sys_attachment'); gr.addQuery('table_sys_id',currentImage); gr.query(); if(gr.next()){ UrlImageSysId=gr.sys_id; } return UrlImageSysId; }, type: 'AttachmentAjaxUtil' });
- Create a Client Script using GlideAjax to fetch that sys_id
var ga = new GlideAjax('AttachmentAjaxUtil'); ga.addParam('sysparm_name','getAttachmentSysId'); ga.addParam('sysparm_currentImage',g_list.getChecked()); ga.getXML(showPopup); function showPopup(response) { var UrlImageSysId= response.responseXML.documentElement.getAttribute("answer"); url = 'https://hpindigodev.service-now.com/'+UrlImageSysId+'.iix'; g_navigation.openPopup(url); //this is preferable to window.open - window is not supported API, will probably be flagged in health checks }
Let me know if you have issues with your GlideAjax.
Please note the code provided has not been tested. Use at your own risk!
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
04-02-2019 11:48 AM
Hi,
If this UI action is client side, then you'll need to use a different method for opening URL in new tab.
If this is server side, you can try:
window.open(url, '_blank');
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 12:21 AM
thanks for your comment,
I am using server-side script, I tried that one and it's doesn't work (it's open the same page again..)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 05:38 AM
Hi, can you try:
g_navigation.openPopup(url);
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 06:15 AM
It is not possible to open a new tab or window in a browser by server-side code alone. You can only choose the next page shown.
When you think about it - the server cannot control the browser on a client's computer. If it could, that would be a massive security flaw!
You need to do it with both Client and Server Scripts.
This is how:
- Write a Client callable Script include called AttachmentAjaxUtil with your attachment fetch script that takes currentImage as a parameter and returns UrlImageSysId
var AttachmentAjaxUtil = Class.create(); AttachmentAjaxUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, { getAttachmentSysId: function() { var UrlImageSysId='';//image sysId for url param var url='';//url for redirect var currentImage = this.getParameter('sysparm_currentImage');//current image sysId from 'u_ts_image' table var gr = new GlideRecord('sys_attachment'); gr.addQuery('table_sys_id',currentImage); gr.query(); if(gr.next()){ UrlImageSysId=gr.sys_id; } return UrlImageSysId; }, type: 'AttachmentAjaxUtil' });
- Create a Client Script using GlideAjax to fetch that sys_id
var ga = new GlideAjax('AttachmentAjaxUtil'); ga.addParam('sysparm_name','getAttachmentSysId'); ga.addParam('sysparm_currentImage',g_list.getChecked()); ga.getXML(showPopup); function showPopup(response) { var UrlImageSysId= response.responseXML.documentElement.getAttribute("answer"); url = 'https://hpindigodev.service-now.com/'+UrlImageSysId+'.iix'; g_navigation.openPopup(url); //this is preferable to window.open - window is not supported API, will probably be flagged in health checks }
Let me know if you have issues with your GlideAjax.
Please note the code provided has not been tested. Use at your own risk!
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022