pass values to an array based on condition

Priti18
Tera Expert

how can I push some hard coded values to an array based on some condition.

if user is having role itil

then add user having itil role is added to list in short description field

9 REPLIES 9

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Priti18 ,

In order to push values in array you can simply use :

var arr=[];
arr.push('yourValue/Field');

 I'm confused with your 2nd requirement, Do you want to add short description on incident or any other table on the basis of caller /assigned to ? Please elaborate more.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Priti18
Tera Expert

Hi @Gunjan Kiratkar 

 

am quering some table and getting values inside array 

for eg if user is A then push value abc 

if user is B then push value xyz // now these values comes from table

but only for one user lets say if user is C then push value " user is from different group" // now this I want to be hardcoded... for this user i dont want table to be queried and then pushing values to array

and result should be  result = ["abc","xyz","user is from different group"}

@Priti18 ,

If you could provide your script then it will be easy for me to edit that.

Sample Script :-

var arr=[]; //Empty Array
var gr=new GlideRecord('sys_user');
gr.query();
while(gr.next()){
if(gr.user_name=='B'){
arr.push(gr.getValue('name'));
}else if(gr.user_name=='C'){
arr.push("user is from different group");
}

}

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Shashank_18
Mega Guru

@Priti18 ,

 

You have to use if/else statement to push the desired outcome to array. 

Array.push method will be used to push the value in array.