Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch array if it contains particular string?

Gayathri5
Tera Guru

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

 

17 REPLIES 17

@Gayathri 

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

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Gayathri 

Any update on this?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Gayathri 

Any update on this?

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@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
}
}

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader