Jason Values

Kanna12
Tera Expert

I have cretaed Sys_property : Authorization group where i have added values.

{"group value":"group sys_id",

"group value"1:"group sys_id1",

"group value2":"group sys_id2"

}

 

In the workflow if i  selected one group workflow needs to send an approval to remaining groups  (not current group which i selected).

I written below code but it is sending to all 3 groups.

 

var GroupProperty=jsonProperty.parse(gs.getProperty('Authorization group'));

for(var i in GroupProperty) {
if( i!== currentChgCreationGrp) {
answer.push(GroupProperty[i]);
}
}

 

 

Could any one please help this much appreciated!

Thank you,

Gayam

2 ACCEPTED SOLUTIONS

Adrian Ubeda
Mega Sage
Mega Sage

Hello @Kanna12 ,

I'd recommend you to use a separeted-comma value in the sys_property instead using JSON structure, I let you a useful code for pop out value from array when it's found:

var groups = '019ad92ec7230010393d265c95c260dd,477a05d153013010b846ddeeff7b1225,553032e853165110b846ddeeff7b12aa';
var arrGroups = groups.split(',');
var index = arrGroups.indexOf('477a05d153013010b846ddeeff7b1225');
if (index > -1) { // only splice array when item is found
  arrGroups.splice(index, 1); // 2nd parameter means remove one item only
}
gs.info(arrGroups);
If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

View solution in original post

my original Properties are
{"it_dev":"f5ecc7a31b7dbd10bf2210ad9c4bcb16",
"it_test":"026d87a31b7dbd10bf2210ad9c4bcb85",
"it_preprod":"187d0fa31b7dbd10bf2210ad9c4bcb1e",
"it_prod":"388d0fa31b7dbd10bf2210ad9c4bcb20"
}

View solution in original post

6 REPLIES 6

Adrian Ubeda
Mega Sage
Mega Sage

Hello @Kanna12 ,

I'd recommend you to use a separeted-comma value in the sys_property instead using JSON structure, I let you a useful code for pop out value from array when it's found:

var groups = '019ad92ec7230010393d265c95c260dd,477a05d153013010b846ddeeff7b1225,553032e853165110b846ddeeff7b12aa';
var arrGroups = groups.split(',');
var index = arrGroups.indexOf('477a05d153013010b846ddeeff7b1225');
if (index > -1) { // only splice array when item is found
  arrGroups.splice(index, 1); // 2nd parameter means remove one item only
}
gs.info(arrGroups);
If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Thank you!
Much appreciated

Harsh Vardhan
Giga Patron

Hi @Kanna12  Can you double check the properties values are correct because i noticed json key is appearing like "group value"1 , it should be "group value1

 

also please update your if block condition script. eg: 

 

var GroupProperty=jsonProperty.parse(gs.getProperty('Authorization group'));

for(var i in GroupProperty) {
if(  GroupProperty[i] != currentChgCreationGrp) {
answer.push(GroupProperty[i]);
}
}

 

I tested on my personal instance with below eg and it worked. 

 

var jn = {"group value":"group sys_id","group value1":"group sys_id1","group value2":"group sys_id2"};

var jnn = JSON.stringify(jn);
var currentChgCreationGrp = "group sys_id";
var GroupProperty=JSON.parse(jnn);
var answer =[];
for(var i in GroupProperty) {
if( GroupProperty[i] != currentChgCreationGrp) {
answer.push(GroupProperty[i]);
}
}

gs.print(answer);

 

Hope it will help you.

 

Thanks,

Harsh

my original Properties are
{"it_dev":"f5ecc7a31b7dbd10bf2210ad9c4bcb16",
"it_test":"026d87a31b7dbd10bf2210ad9c4bcb85",
"it_preprod":"187d0fa31b7dbd10bf2210ad9c4bcb1e",
"it_prod":"388d0fa31b7dbd10bf2210ad9c4bcb20"
}