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.

Get Multiple Values from one key in system properies

Nasir1
Tera Expert

Good Morning guys,

I have a system property, with multiple keys in it, and each key has multiple values in it, I am hoping if someone can please help me with a script that can fetch the values of the key from the system property.

 

System Property Name = my_test_property;

 

These are the values in my system property

 

{
"Profile1" : "Portal_1","Portal_2",
"Profile2" : "Portal_3","Portal_4",
}

 

1 ACCEPTED SOLUTION

Johns_MP
Giga Guru

Hi @Nasir1 ,

Will you be able to change your property as below:

{
"Profile1" : ["Portal_1","Portal_2"],
"Profile2" : ["Portal_3","Portal_4"]
}

 

if yes, then this code might work for you

var prop = gs.getProperty('test_community_property_1'); //give the name of your property
var jsonObj = JSON.parse(prop);
var keyNeeded = 'Profile1'; //give the key you need
var values = jsonObj[keyNeeded];
gs.print(values);

 

you will get the values as below:

Screenshot 2023-01-13 at 12.20.25 PM.png

Mark helpful if it helps in Solving your query

Regards,
Johns M P

View solution in original post

2 REPLIES 2

Johns_MP
Giga Guru

Hi @Nasir1 ,

Will you be able to change your property as below:

{
"Profile1" : ["Portal_1","Portal_2"],
"Profile2" : ["Portal_3","Portal_4"]
}

 

if yes, then this code might work for you

var prop = gs.getProperty('test_community_property_1'); //give the name of your property
var jsonObj = JSON.parse(prop);
var keyNeeded = 'Profile1'; //give the key you need
var values = jsonObj[keyNeeded];
gs.print(values);

 

you will get the values as below:

Screenshot 2023-01-13 at 12.20.25 PM.png

Mark helpful if it helps in Solving your query

Regards,
Johns M P

Nasir1
Tera Expert

Brilliant, thank you so much this is works now.