how to open a new tab when you click a UI Action button?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 10:25 AM
here is script i am using in my UI Action:
var change = new GlideRecord("change_request");
change.initialize();
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.assigned_to = current.assigned_to;
var changesysID = change.insert();
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
i am trying to open a new tab when i click on a UI Action button.
any help would be appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2021 10:36 AM
Hello Faraz,
Please try using below method:
Do check the client checkbox on the UI action form.
Pasting the code for your convenience:
function viewChangeList(){
var url = 'change_request_list.do?sysparm_userpref_module=3264ded3c611227a019523c8448d2d91&sysparm_clear_stack=true'; //link for change request table
g_navigation.openPopup(url);
}
Please try it and update the results.
Regards,
Soumya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2021 06:53 PM
Hi Soumya,
Thanks for your response but this is not what i am looking for.
i am creating a change request from incident and i have already achieve that but my problem is, I am trying to open that change request in a new tab or window.
on my incident form i have created a UI action button to create a change request and when i click on that button it should open a change request with some auto populated fields (which is working fine) i just want that change request should open in a new window.
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 01:16 PM
Your code looks as if it is server side code. It is not possible to dictate whether the redirection ends up in a new window/tab or in the same window/tab from server side. It will always be the same window/tab. In order to accomplish opening the new change in a new tab you have a couple of options:
1. make the UI Actin to be client side UI Action and let the button open an new (temporary) Change Request in a new tab, using the g_navigation
API, perhaps encoding values in the URL to be opened and once opened, applying those values to the new (temporary) Change Request using an onLoad Client Script.
2. Create a display BR on the creator record that somehow figures out that you just created a new Change Request server side and that it needs to be opened in a new windows/tab and let it set some flag on g_scratchpad
. Then have a Client Script on the same creator record look for that flag on each load and have it open the created Change Request in a new tab using one of the methods mentioned by others. Of course that means that one presses the button on your original record, the original record is reloaded and when reloading is done, a new tab will be opened with the new Change Request.
But, again, it is not possible from server side. Not because of SN, not because of UI Actions, but because of HTTP (the protocol used by browsers to communicate with web servers).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2021 01:56 AM
Hello
are you using both in your Script? as I have highlighted.
var change = new GlideRecord("change_request");
change.initialize();
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.assigned_to = current.assigned_to;
var changesysID = change.insert();
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
the highlighted will get you to stay on same page.
if you want to redirect new page use below
You need to use Instance URL Dynamic, else you will lose things after upgrade and Clone.
below line of code will help you to get instance url
var instanceURL = gs.getProperty('glide.servlet.uri');//this will give you your instance url as http//:dev12345service-now.com/
setRedirectURL(instanceURLsys_id=changesysID);
changesysID// this is your variable having sys_id of record
please make small change as per your requirement. / or small issue may come here.
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2021 03:19 AM
Hello
Please try in this way and let me know, whether this works or not?
as per my previous answer " instanceURL" will give you instance URL
action.setRedirectURL(instanceURL/change_request.do?sys_id=changesysID &sysparm_record_target=change_request);
Please provide feedback, it works or not?
I haven't tried this practically, its just a sugeesion
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat