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.

Does not contain

Akhil kumar Avu
Tera Contributor

Hi,

I want to filter records on incident table with reference field "assignment_group doesn't contain network". 

 

var gr = new GlideRecord('incident');

gr.query(),

if(gr.assignment_group.name!="net") //I have used this way and tried with indexOf but it is not working.  i want to filter "assignment_group doesn't contain net" through only  if condition not encoded query

{

 

}         

Thanks in advance!!

1 ACCEPTED SOLUTION

Hi 

You can try this

below code check if assignment group name does not have word 'network'  and prints the incident number.

var gr = new GlideRecord('incident');
gr.query();
while(gr.next()){
        if(gr.assignment_group.name.toLowerCase().indexOf('network') < 0){
                gs.info(gr.number);
        }
}

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

10 REPLIES 10

Murthy Ch
Giga Sage

Hi @Akhil kumar Avu 

If you don't want to use via encoded query then you have to use add query like below:

var grI=new GlideRecord("incident");
grI.addQuery("assignment_group.name", "DOES NOT CONTAIN", "network");
grI.query();
while(grI.next())
{
gs.info(grI.number.toString());
}

Hope it helps.

Thanks,
Murthy

Thank you for quick reply. I don't want to use addQuery also. I want to filter through if condition. Please help on this.

 

Mohith Devatte
Tera Sage
Tera Sage

Hello @Akhil kumar Avu ,

try this script 

in the script replace your network assignment group sys_id.

To copy the sys_id go to sys_user_group.LIST table and then search for network record and then right click on it and copy the sys_id like below 

Screenshot 2022-11-24 at 19.59.04.png

 

var gr = new GlideRecord('incident');

gr.addEncodedQuery('assignment_group!=287ebd7da9fe198100f92cc8d1d2154e'); //replace network group sys_id

gr.query();

while(gr.next())

{

//your logic

}

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

Voona Rohila
Mega Patron
Mega Patron

Hi @Akhil kumar Avu 

you can use 'NOT LIKE' in the query.

Try this 

 

 

 

var grI=new GlideRecord("incident");
grI.addQuery("assignment_group.nameNOT LIKEnet");
grI.query();
while(grI.next())
{
gs.info(grI.number.toString());
//do something.
}

 

 

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP