pass values to an array based on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 04:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 05:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 05:33 AM
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"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 05:40 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 05:46 AM
@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.