Do we have LIKE / NOT LIKE conditions in ServiceNow to use in Scripting ?

Sama4
Kilo Expert

Hi,

Do we have LIKE/NOT LIKE conditions which can be used in add Query of the script. ?   Just like below in SQL:

SELECT * FROM Customers

WHERE Country NOT LIKE '%land%';

7 REPLIES 7

michal29
Mega Guru

Hello sarvamangala,



Actualy to achieve this you can use:



var gr = new GlideRecord('CUSTOMERS');


gr.addQuery('country', 'DOES NOT CONTAIN', 'land');


gr.query();


while(gr.next()){


// Results....


}



Take a look at: Using GlideRecord to Query Tables - ServiceNow Wiki



Regards,


Michal


Can we use just an input parameter to check for 'CONTAINS/DOES NOT CONTAIN' function.


Exp:



gr.addQuery('country',DOESN NOT CONTAIN', input_parameter); // input_parameter is the value which is being passed from web services , so its not constant.


Yes,


but that depends on how you got this parameter, lets say:



var Your_parameter   =   Whatever_way_you_retrieve_it


Your_parameter = Your_parameter.toString();


var gr = new GlideRecord('CUSTOMERS');


gr.addQuery('country',DOESN NOT CONTAIN', Your_parameter);


gr.query();


while(gr.next()){


}



Regards,


Michal


In case anyone comes here looking for the info and finds the wiki links down:

https://servicenowguru.com/scripting/gliderecord-query-cheat-sheet/

 

Regards,

N.