Servicenow array samples

Tiago Macul
1 min readDec 3, 2020

--

MyCustomTables = Getmultiplevalues();
gs.print(‘FULL Value = ‘ + MyCustomTables);
gs.print(MyCustomTables[0]);
gs.print(MyCustomTables[1]);
gs.print(MyCustomTables[2]);

function Getmultiplevalues()
{
var strReturn = [];

var grMult = new GlideRecord(“ua_custom_table_inventory”);
grMult.setLimit(3);
grMult.query();
while(grMult.next()) {
gs.print(grMult.table_name);
strReturn.push(grMult.table_name)
}

return strReturn;
}

====================================

x = testing();
gs.print(x);

function testing()
{
var sysIDkey = [];
var GRtables = new GlideRecord(‘ua_custom_table_inventory’);
GRtables.setLimit(3);
GRtables.query();
while (GRtables.next()) {
sysIDkey.push(GRtables.getValue(‘sys_id’));
}
return sysIDkey.join(‘,’); // return comma separated string of sys_ids
}

====================================

Hard work, building a join function

function testing()
{
var sysIDkey = [];
var GRtables = new GlideRecord(‘ua_custom_table_inventory’);
GRtables.setLimit(3);
GRtables.query();
while (GRtables.next()) {
sysIDkey.push(GRtables.getValue(‘sys_id’));
}
// return sysIDkey.join(‘,’); // return comma separated string of sys_ids

return arrayToString(sysIDkey);
}

function arrayToString(arr) {
var str = ‘’;
arr.forEach(function(i, index) {
str += i;
if (index != (arr.length — 1)) {
str += ‘,’;
};
});
return str;
}

--

--

No responses yet