Does Not starts with condition in addQuery

Pihu1
Tera Contributor

Hi Community,

I need help in filtering the records , which does not starts with in addQuery() method. How can we achieve this?

Any help would  be greatly appreciated.

Thanks,

Pihu

1 ACCEPTED SOLUTION

Hi,

Sample below

var arr = [];

var rec = new GlideRecord('incident');

rec.query();

while(rec.next()){

var startsWith = rec.caller_id.name.startsWith('AB'); // this will give false when doesn not starts with

if(startsWith.toString() == 'false'){

arr.push(rec.number.toString());

}

}

gs.info('Incidents where caller name does not start with AB'+ arr);

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

doesn not starts with is not available as filter operator

So you will have to determine the condition by iterating the records using while loop

Regards
Ankur

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

Thanks Ankur.

Can you please help with the condition - Server name does not starts with A0 or A1.

Thanks,

Pihu

Hi,

Sample below

var arr = [];

var rec = new GlideRecord('incident');

rec.query();

while(rec.next()){

var startsWith = rec.caller_id.name.startsWith('AB'); // this will give false when doesn not starts with

if(startsWith.toString() == 'false'){

arr.push(rec.number.toString());

}

}

gs.info('Incidents where caller name does not start with AB'+ arr);

Regards
Ankur

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

Thanks! Ankur.It worked for me.