How can i write this UI action so that the url opens in a new browser tab?

Ub11
Mega Expert

Please can someone help me write this UI script so that it opens up the URL in a new browser tab.

var url = '/u_missing_ci.do?sys_id=-1';
url += '&sysparm_query=';
url += 'u_raised_by=' + gs.getUserID();
url += '^u_originating_task=' + current.sys_id;
url += '^u_assignment_group=' + gs.getProperty('si.missing_ci.default_assignment_group');
action.setRedirectURL(url);
action.setReturnURL(current);

 

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

unfortunately you cannot open in new tab in server side using action object

please use client side and below code and it would open in new tab

sharing one link here where I have replied previously

https://community.servicenow.com/community?id=community_question&sys_id=1f4bf5fcdb3fc41813b5fb243996...

Note: This won't work in client side; so either do glide ajax to get the property value or hard-code the sys_id

gs.getProperty('si.missing_ci.default_assignment_group');

UI Action:

function openRecord(){

	var ga = new GlideAjax('getPropertyUtils');
	ga.addParam('sysparm_name', "getPropertyValue");
	ga.getXMLWait(); 
	var propertyValue = ga.getAnswer();

	var url = '/u_missing_ci.do?sys_id=-1';
	url += '&sysparm_query=';
	url += 'u_raised_by=' + g_user.userID;
	url += '^u_originating_task=' + g_form.getUniqueValue();
	url += '^u_assignment_group=' + propertyValue;

	g_navigation.openPopup(url);
}

Script Include: Client Callable true

var getPropertyUtils = Class.create();
getPropertyUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getPropertyValue: function(){
		return gs.getProperty('si.missing_ci.default_assignment_group');
	},


	type: 'getPropertyUtils'
});

Screenshots:

find_real_file.png

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

unfortunately you cannot open in new tab in server side using action object

please use client side and below code and it would open in new tab

sharing one link here where I have replied previously

https://community.servicenow.com/community?id=community_question&sys_id=1f4bf5fcdb3fc41813b5fb243996...

Note: This won't work in client side; so either do glide ajax to get the property value or hard-code the sys_id

gs.getProperty('si.missing_ci.default_assignment_group');

UI Action:

function openRecord(){

	var ga = new GlideAjax('getPropertyUtils');
	ga.addParam('sysparm_name', "getPropertyValue");
	ga.getXMLWait(); 
	var propertyValue = ga.getAnswer();

	var url = '/u_missing_ci.do?sys_id=-1';
	url += '&sysparm_query=';
	url += 'u_raised_by=' + g_user.userID;
	url += '^u_originating_task=' + g_form.getUniqueValue();
	url += '^u_assignment_group=' + propertyValue;

	g_navigation.openPopup(url);
}

Script Include: Client Callable true

var getPropertyUtils = Class.create();
getPropertyUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getPropertyValue: function(){
		return gs.getProperty('si.missing_ci.default_assignment_group');
	},


	type: 'getPropertyUtils'
});

Screenshots:

find_real_file.png

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks so much Ankur, that is perfect.