- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 01:42 AM - edited 09-18-2023 01:46 AM
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
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 03:57 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 01:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 02:01 AM
Tried both of these , no of them worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 09:13 AM
Out of luck. Anything else that I can try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 09:55 PM
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.