how to open a ui action link in a new tab

asd22
Tera Contributor

Hello, i have a ui action button with this script. how do i make it so that the url gets opened in a new tab?

 

createRITM();
function createRITM() {
var tableName = 'alm_hardware';
        var viewName = 'registrering_av_hardware_ved_innkjøp'; // give your view name
        var po_number = current.u_uh_nr|| '';
        var sys_id = current.sys_id || '';
        var req_for = current.request.requested_for|| '';
action.setRedirectURL('https://testingnow.com/alm_hardware.do?sysparm_view=registrering_av_hardware_ved_innkj%C3%B8p&syspar...);

}

1 ACCEPTED SOLUTION

Hi @asd22 ,

Please check the Client option. This should resolve your issue.

View solution in original post

6 REPLIES 6

Basheer
Mega Sage

Hi @asd22 

get the url which you want in comments.

var url = 'https:/servicenow.com/';
window.open(url,'_blank');

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

asd22
Tera Contributor

do you mean like so? 

asd22_0-1674043193382.png

 

Hi @asd22 ,

 

In your code, client checkbox is unchecked i.e. this UI action will be run at server side. It is not possible to open a new tab or window in a browser by server-side code alone. 

You need to do it with both Client and Server Scripts.

Please refer the below thread to achieve the functionality :

https://www.servicenow.com/community/developer-forum/ui-action-redirect-to-a-new-window-tab-using-se...

 

You can take reference of the code mentioned in the above thread, try to configure server side logic in Client callable ScriptInclude and call script include in Clientscript using GlideAjax method.

OR

You can make/try the UI action client callable(Client checkbox should be true) and use top.window.open(url); to open the URL in new tab. Please see the below screenshot of test script.

 

Jyoti4_0-1676915169541.png

 

 

 

Please mark reply as Helpful/Correct/Accept Solution, if applicable. Thanks!

 

Thanks & Regards

Jyoti Jadhav

I tried a ui action with client set to true and this script:

var url = 'entered url here';
top.window.open(url);
It will only open the link in a new tab after the current page reloads.  Any thoughts?