'Does Not Start With' Operator

niitnishant
Tera Contributor

Hi Friends,

I am in process of creating a report on Incident table. Require a suggestion on filter criteria please-

This is the filter criteria below i need to set (along with other simple condtions)-

CIs 'Do not Start With'- SAP , EAS, E1

Assignment Groups 'Do not Start With'- EAS, SAP, DBA, LSG.E1

While there is a 'Starts with' but no 'Does not start with' in ServiceNow. Any experience , thought will be highly appreciated.

Thanks,

Nishant

10 REPLIES 10

RamSagar
Tera Guru

did you find the solution   for finding not starts with


Anantha Gowrara
Kilo Sage

Hi All,

Even i had similar requirement to restrict groups which has some selected prefixes.I have implemented this requirement using before query business rule as below and it works perfect.

 

(function executeRule(current, previous /*null when async*/) {

              var group_prefix = gs.getProperty('GroupPrefixes'); // replace with your system property

              var group_splitted = group_prefix.split(',');

              var query = 'nameSTARTSWITH'+group_splitted[0];

              for(var i=1;i<group_splitted.length;i++){

                             query = query+"^ORnameSTARTSWITH"+group_splitted[i];

              }

              var final_groups =[];

              var allGroups = new GlideRecord('sys_user_group');

              allGroups.addEncodedQuery(query);

              allGroups.query();

              while(allGroups.next()){//final_groups.push(allGroups.sys_id);

                             current.addQuery('sys_id','!=',allGroups.sys_id);

              }

 

  Please mark this answer as correct if this helps.

 

Regards

Anantha Gowraram

 

But this requires the system property to be updated as per the needs, isn't it?

Filip Vojt__ek
Mega Guru

Hi Nishant,

 

it's a while ago, but maybe someone will find this answer helpfull.

 

The solution from my point of view is to use 'LIKE' operator which work even though it's not documented:

gr.addQuery('name', 'NOT LIKE', 'SAP%');
gr.addQuery('name', 'NOT LIKE', 'EAS%');
gr.addQuery('name', 'NOT LIKE', 'E1%');

 

Pls mark as helpful if solution works.

Hi All,

 

I am trying the same approach to  exclude groups that start with ECAB or KNOWLEDGE; it should also exclude groups that have the 'mic' group type. So i have tried with the background script with Not Like operator like below code.

 

 //var query = "nameSTARTSWITHECAB^ORnameSTARTSWITHKNOWLEDGE^ORtypeLIKE704093f22b08224072751cf405da1599";
//var query = "nameSTARTSWITHECAB";

//var rev ="!" + query;
var l1 = new GlideRecord('sys_user_group');
l1.addQuery('name', 'NOT LIKE', 'ECAB%');
l1.addQuery('active', true);
l1.query();
while(l1.next()){
    gs.print(l1.getRowCount());
    gs.print(l1.name);
}
 
 
I have tried with One condition and it is working as expected but i want to include other two conditions.
conditions : Group does not start with ECAB or Group does not start with Knowledge and Type is not Mic.
 
Thanks,
Apoorva