Issue with opening multiple sub tabs in workspace client script using g_aw.openRecord

Snehal13
Kilo Sage

This code is written in workspace client script section of a UI action. This work fine but opens only 1 tab. I want to open 3 tabs.

 

for (var i=0; i<3; i++) {
          var user_query = '^first_name=Anthony';
          g_aw.openRecord("sys_user", "-1", {"query": user_query }); // -1 because it is a new record and no sys id
}

 

1 ACCEPTED SOLUTION

sarahakers
Tera Guru

I was finally able to get this to work and open mulitple tabs. Prior to doing so it would open the last tab.  

I had to implement the timeout and call it from the loop instead of nesting it in the loop. It should have worked just fine the way @Ratnakar7 has it outlined but it didnt. 

 

I had to adjust to

 

for (var i =0; i<answer.length; i++){

timeMe(answer[i].table, answer[i].sys_id)

}

function timeMe(table,sysid){

setTimeout(function(){

g_aw.openRecord(table,sysid);

},1000);

}

View solution in original post

5 REPLIES 5

Ratnakar7
Mega Sage
Mega Sage

Hi @Snehal13 ,

 

You can use a timeout to delay the opening of each subsequent sub-tab. This allows ServiceNow some time to process each request before opening the next tab. Here's an example:

var user_query = '^first_name=Anthony';

function openSubTab() {
    g_aw.openRecord("sys_user", "-1", { "query": user_query });
}

for (var i = 0; i < 3; i++) {
    setTimeout(openSubTab, i * 1000); // Open tabs with a 1-second delay (adjust as needed)
}

 

OR, you can modify the query or record sys_id slightly for each sub-tab. For example:

var users = ["Anthony", "John", "Jane"];

for (var i = 0; i < users.length; i++) {
    var user_query = '^first_name=' + users[i];
    g_aw.openRecord("sys_user", "-1", { "query": user_query });
}

 

Thanks,

Ratnakar

Tried both of these , no of them worked.

Out of luck. Anything else that I can try

Snehal13
Kilo Sage

Both of the code only open 1 sub tab. I already have the flow for 1 subtab. Need to open multiple subtabs based on count of users from form.