How to fetch array if it contains particular string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 09:29 PM
Hi All,
I have array it contains
var allarr =[];
var incarr =[];
allarr=INCXXXX, INCXXXX, PRBXXXX, SCTXXXXX, PRBXXXX;
now i am checking if allarr contains INC separate it in another array which is not working
for(var x in allarr){
gs.log("Inside for loop:"+allarr);//going here
if(allarr[x].indexof('INC') > -1){
incarr.push(allarr[x]);
gs.log("Inside if:"+incarr); //not going inside if loop
}
}
after going inside if loop i want to separate all incidents in one array, can any one help me pls
Regards,
Gayathri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 11:30 PM
your original question was about getting the incidents from the array which I have provided solution above.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 11:05 PM
Any update on this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 12:24 AM
Any update on this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 10:40 PM
@Ankur,
Please have a look, where i am going wrong
Workflow Script
var gr1 = new GlideRecord("sys_user_grmember");
gr1.addQuery('group', Grps1);
gr1.addQuery('user', reqforsysid);
gr1.query();
if (gr1.next()) {
var array = [];
var tsk = new GlideRecord('task');
tsk.addQuery('active', 'true');
tsk.addQuery('assignment_group', Grps1); //tsk.addEncodedQuery('sys_class_name=sc_task^ORsys_class_name=incident^ORsys_class_name=change_request^ORsys_class_name=problem^assigned_to=' + reqsysid + '^stateNOT IN3,4,0,7,106,107,157');
tsk.addEncodedQuery('sys_class_name=sc_task^ORsys_class_name=incident^ORsys_class_name=change_request^ORsys_class_name=problem^assigned_to=' + reqforsysid + '^stateNOT IN3,4,0,7,106,107,157');
tsk.query();
while (tsk.next()) {
array.push(tsk.number.toString());
tsk.assigned_to = formmanager;
tsk.update();
}
gs.eventQueue('te.notify.manager', current, array, formmanager);
//email script
var eve1 = event.parm1;
var arpb=[];
var arrprb =[];
arpb.push(eve1.toString());
gs.log("$Adding Event in array:"+arpb);
for(var x in arpb){
gs.info("@Inside for loop:"+arpb);
if(arpb[x].indexOf('PRB') > -1){
arrprb.push(arpb[x].toString());
gs.info("@Inside if:"+arrprb); //here i am getting all task numbers including prb, inc etc
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 11:20 PM
Hi,
your original question was about getting the incidents from the array which I have provided solution above.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader