How to split comma separated string into array and query correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2021 07:22 PM
I created an array (allQueues) which lists some companies from the core_company table. From there, I am obtaining each companies’ sub-queues (u_phone_queue) string field which is listed in a comma separated list. Afterwards, the sub-queues should be split up and populated into an array, where they are queried on another table to obtain stats like ‘Total Calls Daily’ for each queue.
Example:
allQueues | u_phone_queue | (COUNT) | (Total Calls Daily) |
Company A | SubQueue 1,SubQueue 2 |
SubQueue 1 (5) SubQueue 2 (8) |
13 |
Company B | SubQueue 3,SubQueue 4, SubQueue 5 |
SubQueue 3 (4) SubQueue 4 (10) SubQueue 5 (2) |
16 |
Company C | SubQueue 6,SubQueue 7,SubQueue 8,SubQueue 9 |
SubQueue 6 (5) SubQueue 7 (10) SubQueue 8 (12) SubQueue 9 (7) |
34 |
Company D | SubQueue 10,SubQueue 11 |
SubQueue 10 (1) SubQueue 11 (7) |
8 |
var allQueues = ['Company A', 'Company B', 'Company C', 'Company D'];
var subStr;
var outputSplit;
for (i = 0; i < allQueues.length; i++) {
// Obtain sub-queues
var queueAgg = new GlideRecord('core_company');
queueAgg.addQuery('name', allQueues[i]);
queueAgg.query();
while (queueAgg.next()) {
subStr = queueAgg.getValue('u_phone_queues');
outputSplit = subStr.split(' ');
}
// How to add outputSplit to subArr array?
var subArr = [];
// Total Calls Daily
var totalCallsDaily = 0;
var countDaily = new GlideAggregate('u_connect_contact_trace_records');
countDaily.addQuery('u_queue_name', subArr[i]);
countDaily.addQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
countDaily.addQuery('u_agent_usernameISNOTEMPTY');
countDaily.addAggregate('COUNT');
countDaily.query();
if (countDaily.next()) {
totalCallsDaily = countDaily.getAggregate('COUNT');
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2021 08:11 PM
Hi, you should be able to assign subStr directly to your array using split
try something like
var subStr = '1 2 3 4 5 6';
var subArray = subStr.split(' ');
gs.info(subArray[2]);