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

Priti18
Tera Expert

with regards to above code how can I add else if inside array

 

here if gr.user_name == C then 

arr.push (gr.getvalue(name came from A, B)+ " user is from different group) // this is how i want it to be

var gr = new GlideRecord(tablename);
gr.addQuery(your query);
gr.query()
while(gr.next())
{
if(gr.user_name =="A")
{
arr.push(dynamic value);
}
else if(gr.user_name == "B")
{
arr.push(dynamic value 2);
}
else if(gr.user_name =="C")
{
arr.push("user does not exist");
}
gr.short_description= arr.toString();
gr.update();

}

if I have list of sys id inside an array and if I have to check whether it contains one of them then how can I get it

 

for eg. array = [1,2,3,4,5,6]

if array contains 2 then go inside loop or else skip

var arr = ['1errrr444','2abc4','11212ww','4eweqw11','5sdasdsa','6zcxcz555'];
if(arr.indexOf("2abc4")>0)
{
gs.print("found");
}
else{
    gs.print("not found");
}

hi Shashank,

 

above code is working just want to add few condition

var arr = ['1errrr444','2abc4','11212ww','4eweqw11','5sdasdsa','6zcxcz555'];
if(arr.indexOf("2abc4")>0)
{
lets say 2abc4 already has user_name as A in the table now I want to replace the value of and keep it as B // then how to achieve this
}