Open a new tab within UI Action

georgechen
Kilo Guru

Hello, everyone,

I am raising this questions for my colleague who is having a question about creating new tab within an UI action (Server-side script).   He is working on a form button (a UI action) that needs to open a new tab (see Start Exam button below)

find_real_file.png

and below is the script underneath, the UI Action is expected to perform thing like what client script does,   window.location = 'expert_shell.do?sysparm_sys_id=4f0a1b3538f695002ae704ffa136f274&sysparm_initial=true&sysparm_view=wizard';

referring to action.setRedirectURL not working it is suggested to use action.setRedirectURL(), but is there a way to open the URL in a new tab?

Any advice would be appreciated.

Regards,

var gdw = new GlidePaneForm('Approvers', 'kb_view');

                      gdw.addParm('sysparm_article', number);

                      gdw.render();

// Start the Exam

current.u_started = gs.nowDateTime();

current.update();

//Put you on the First question

var response = new GlideRecord("u_lms_response");

response.addQuery("u_instance", current.sys_id);

response.addQuery("u_number", 1);

response.query();

if (response.next()) {

     

      var url = "u_lms_response.do?sys_id=" + response.sys_id + "&sysparm_view=&sysparm_record_target=&sysparm_record_row=1&sysparm_record_list=u_instance=" + current.sys_id + "&ORDERBYu_number";

     

      action.setRedirectURL(url);

      action.setReturnURL(current);

}

var timeToComplete = current.u_time_limit.getDisplayValue();

if (timeToComplete == 0)

  timeToComplete = 'unlimited time';

gs.addInfoMessage('Good luck!   You have ' + timeToComplete + ' to complete this exam.');

// Show the skills at stake

var skillList = '';

var qsk = new GlideRecord('u_m2m_skills_questionnaires');

      qsk.addQuery('u_questionnaire',current.u_questionnair.sys_id);

      qsk.query();

      while (qsk.next()) {

  skillList = skillList + qsk.u_skill.getDisplayValue() + ', ';

      }

if (skillList.length > 0)

              gs.addInfoMessage('Skills at stake: ' + skillList.substring(0, skillList.length - 2));

4 REPLIES 4

Robert Beeman
Kilo Sage

Hi George,



I think this should be possible. SNGuru (link below) describes how to combine client side and server side scripting in one UI Action, but I believe it runs client side first always which wouldn't help you here. I think if you create a UI Action, and select client, then in it do a synchronous Glide Ajax call to a script include (that would basically be the server side code you included in your post), then call whatever method you want on the window object afterward on the client to open your new tab.



Client & Server Code in One UI Action - ServiceNow Guru


Thanks Robert, I will give it a go.


Thanks for your advise.   Much appreciated.


Inactive_Use227
Kilo Contributor

One clever approach you can try is to use a redirect UI page as an interim for more control.


Your redirect URL in the UI Action is something like:


action.setRedirectURL("redirectme.do?sysparm_uri=the-new-url.do,the-old-url.do");



Then redirectme.do is just a blank UI Page (or put a nice spinny loading icon on it), with a redirect script like this:



        var uriLink = "${sysparm_uri}".split(',');


        window.open(uriLink[0], "_blank");


        window.open(uriLink[1], "_parent");



This is a very simplified example that I haven't tried, but you can experiment with this method to achieve the result you desire.


Thanks Jeff, I will give it a go and see this approach works in our scenario.


Your advice is much appreciated.