Would like a URL in workspace to open in a new tab

mrosok
Tera Expert

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. 

 

var str = '<a href="' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '"target=" _blank" >' + 'Open user story' + '</a>';
gs.addInfoMessage("User story is created: " + str);

 

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

1 ACCEPTED SOLUTION

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

View solution in original post

7 REPLIES 7

Thank you Fabian,

 

This does indeed work. It is a hacky method, and I suspect it might break at some point in the future, but I'll try working with this for now.


Thanks again for your help,

Regards

Martin

Hey,

yeah, i do not believe this is intended. Let's hope this feature (not a bug) stays.

Regards

Fabian

Anurag Tripathi
Mega Patron
Mega Patron

Try this

var str = '<a href="' + instance + '/nav_to.do?uri=rm_story.do?sys_id=' + newSysId + '">Open user story' + ' target="_blank"</a>';
gs.addInfoMessage("User story is created: " + str);
-Anurag