- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 04:18 AM - edited 02-09-2024 04:31 AM
We have a UI action "Create Story" on the Incident form. It updates a few fields on the incident record, and makes an infobox with a URL to a newly created Story.
When viewed in a workspace, the link will open the story record in a new workspace tab. This form is not configured for workspace and we would rather it opened in a new browser tab. The user can manually force the link to open in a new tab and it will open in the standard next experience view.
Is there any way I can configure this URL to force open in a new browser window?
Edit: corrected code
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 01:39 AM - edited 02-12-2024 02:38 AM
Hi,
I got it working. And it's super weird:
function onLoad() {
//Type appropriate comment here, and begin script below
var sys_id = g_form.getUniqueValue();
var str = '<a href="//YOURINSTANCENAME.service-now.com/incident.do?sys_id=804b865adb8274d0cf4143ea13961931" target="_blank" rel="noreferrer noopener">Open user story</a>';
g_form.addInfoMessage("User story is created: " + str);
}
// with your example:
var str = '<a href=//"' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '">Open user story' + '<target="_blank" rel="noreferrer noopener"/a>';
gs.addInfoMessage("User story is created: " + str);
So here is my assumption what is happening:
ServiceNow checks, if the link is within your instance
The reason i am pretty sure about this is, that if you are using any other links outside of your instance (e.g. https://www.google.com) it will just open it fine in a new tab. For all links within your instance it will try to open that within the workspace.
How we can go around this is by tricking ServiceNow into thinking "huh, this URL is not within your instance". Now, i don't know who wrote the code for this, but i am glad they did it in a sub-optimal way. Because what we can do is add any number of "/" in-front of your instance link (needs to be at least 2). Your browser doesn't really care about this, but apparently the validation by ServiceNow does.
Fun fact: this validation does not run for any worknote links. Also, if you are using the parameter "novalidate" it will open said link exactly once outside of the workspace.
How to do it in worknotes:
[code]<a href="//YOURINSTANCENAME.service-now.com/incident.do?sys_id=804b865adb8274d0cf4143ea13961931" target="_blank" rel="noreferrer noopener">Open user story</a>[/code]
I hope this helps.
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 04:25 AM - edited 02-09-2024 04:26 AM
target="_blank"
<a href="' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '"target="_blank"> Open user story' + '</a>'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 04:26 AM - edited 02-09-2024 04:27 AM
Hey,
I honestly have not tried it with a new tab yet, but adding "target="_blank"" should work.
var str = '<a href="' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '">Open user story' + '<target="_blank" rel="noreferrer noopener"/a>';
gs.addInfoMessage("User story is created: " + str);
Let me know if that works.
Note, for security reasons within browsers, it's best to also add rel="noreferrer noopener".
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 04:34 AM
I'm sorry, the target=_blank was already tried. I removed it to see if it made a difference, and forgot to restore it before pasting the code above.
Apparently it treats target=_blank as a new tab within the workspace and not the browser.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 01:39 AM - edited 02-12-2024 02:38 AM
Hi,
I got it working. And it's super weird:
function onLoad() {
//Type appropriate comment here, and begin script below
var sys_id = g_form.getUniqueValue();
var str = '<a href="//YOURINSTANCENAME.service-now.com/incident.do?sys_id=804b865adb8274d0cf4143ea13961931" target="_blank" rel="noreferrer noopener">Open user story</a>';
g_form.addInfoMessage("User story is created: " + str);
}
// with your example:
var str = '<a href=//"' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '">Open user story' + '<target="_blank" rel="noreferrer noopener"/a>';
gs.addInfoMessage("User story is created: " + str);
So here is my assumption what is happening:
ServiceNow checks, if the link is within your instance
The reason i am pretty sure about this is, that if you are using any other links outside of your instance (e.g. https://www.google.com) it will just open it fine in a new tab. For all links within your instance it will try to open that within the workspace.
How we can go around this is by tricking ServiceNow into thinking "huh, this URL is not within your instance". Now, i don't know who wrote the code for this, but i am glad they did it in a sub-optimal way. Because what we can do is add any number of "/" in-front of your instance link (needs to be at least 2). Your browser doesn't really care about this, but apparently the validation by ServiceNow does.
Fun fact: this validation does not run for any worknote links. Also, if you are using the parameter "novalidate" it will open said link exactly once outside of the workspace.
How to do it in worknotes:
[code]<a href="//YOURINSTANCENAME.service-now.com/incident.do?sys_id=804b865adb8274d0cf4143ea13961931" target="_blank" rel="noreferrer noopener">Open user story</a>[/code]
I hope this helps.
Regards
Fabian