How to open a new window using UI action javascript after clicking a button?

calvinlo
Kilo Explorer

I have tried to create a UI button and want to open a new window with a url using the button.

It seems that window.open does not work and I notice that there is a function action.setRedirectURL().

Does anyone how to open a new window?

14 REPLIES 14

Hi Grant,



to redirect via server-side in a UI Action; please see the following example:



Redirect server side.jpg



However; redirecting will only forward the end user to another screen in the same browser tab/window.




To redirect the end user to another screen in a new browser tab/window via a UI Action; you'll need to work client-side; please see the following example:



Redirect client side.jpg



Kind regards,



Stijn


PriyaRanji
Tera Guru

Hi Calvin,



Good Day



Client : True



Onclick : showValues()



Script :



function showValues() {



var table = g_form.getTableName(); //used to build the table name portion of the URL  



var record = g_form.getUniqueValue(); //used to build the unique ID portion of the URL  



window.open(table + '.do?sys_id=' + record);   /*to open the window in new page*/




}



If this reply helps you, please consider marking it ✅Correct, ��Helpful, or ��Liking it.



Thanks,


Priyanka R





If this reply helps you, please consider marking it ✅Correct, ��Helpful, or ��Liking it.


Hi Priyanka,



Can u pls help me to redirect the url in the same window instead of opening in new window.


The below code will open new window tab :


window.open(table + '.do?sys_id=' + record);



Thanks


Hi Amit,



Good Day



action.setRedirectURL(new_Record);



Please refer the below link for your reference.



http://wiki.servicenow.com/index.php?title=UI_Actions#Using_a_UI_Action_to_Redirect_to_a_URL



Thanks,


Priyanka R


Hi Amit,



Good Day



Use the URL in the following form and which helps redirect on the same tab / window.



var url = "YOUR INSTANCE NAME/sc_req_item/"+current.sys_id+"/sysparm_view=";



action.setRedirectURL(url);



Please refer the below link for your reference:-



http://wiki.servicenow.com/index.php?title=UI_Actions#Using_a_UI_Action_to_Redirect_to_a_URL



If this reply helps you, please consider marking it ✅Correct, ��Helpful, or ��Liking it.



Thanks,


Priyanka R