Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help parsing through the value of a system property

Curtis Hampton3
Kilo Explorer

I have a system property that I created to holds a list of sys_ids from the sys_user_group table.  They are separated by commas in the system property like so:  sysid1, sysid2,sysid3

In using the gs.getProperty function, I'm able to retrieve the values into a string var like so:

var x = gs.getProperty('my_system_property');

My issue is that I need to parse through the result(var x) to pull out all the sys_id's so I can query them via a loop in a script.  Does anyone have any suggestions?

 

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

We used this:

var getGrp = gs.getProperty('my_system_property');
var spl = getGrp.split(',');

for (var i = 0; i < spl.length; i++){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',spl[i]);
gr.query();
while(gr.next()){
gs.print(gr.user.getDisplayValue());
}
}

 

Thanks,
Ashutosh

View solution in original post

2 REPLIES 2

Sebastian R_
Kilo Sage

You can use the following snippet.

Split the property and then loop over the array.

var x = gs.getProperty('my_system_property');
var aGroups = x.split(',');

for (var i = 0; i < aGroups.length; i++){
 var sGroup = aGroups[i];
// Do what ever you want.
}

 

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

We used this:

var getGrp = gs.getProperty('my_system_property');
var spl = getGrp.split(',');

for (var i = 0; i < spl.length; i++){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',spl[i]);
gr.query();
while(gr.next()){
gs.print(gr.user.getDisplayValue());
}
}

 

Thanks,
Ashutosh