Search for values containing a space character (starting with, containing, ends with)

hubertn
Kilo Contributor

I need to report on all assets with a serial number containing 1 or more spaces anywhere in the value.  

1) can wildcards be used in report and filter conditions?   e.g. * " " *

2) how would i represent the space?   escape sequence?  

3) can REGEX be used in reporting?

Thanks in advance!

1 ACCEPTED SOLUTION

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Hubert



You can create a Script Include which will have a function which returns comma separated sys_ids of the desired records. Then the same function can be used as a filter in your table.


E.g: If we want to create a report on the table sys_user where field phone contains any whitespace, we can write following Script Include:


var TestFilter = Class.create();


TestFilter.prototype = {


      initialize: function() {


      },



  getFilter: function() {


  var v = new GlideRecord('sys_user');


  v.addQuery('phone', 'CONTAINS', ' ');


  v.query();


  return v;


  },



      type: 'TestFilter'


};


And then in the report, we can use following (without quotes):


'Business Phone' 'is one of' 'javascript:new TestFilter().getFilter()'



Please refer to Reference Qualifiers - ServiceNow Wiki   for further details.


View solution in original post

7 REPLIES 7

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Hubert



You can create a Script Include which will have a function which returns comma separated sys_ids of the desired records. Then the same function can be used as a filter in your table.


E.g: If we want to create a report on the table sys_user where field phone contains any whitespace, we can write following Script Include:


var TestFilter = Class.create();


TestFilter.prototype = {


      initialize: function() {


      },



  getFilter: function() {


  var v = new GlideRecord('sys_user');


  v.addQuery('phone', 'CONTAINS', ' ');


  v.query();


  return v;


  },



      type: 'TestFilter'


};


And then in the report, we can use following (without quotes):


'Business Phone' 'is one of' 'javascript:new TestFilter().getFilter()'



Please refer to Reference Qualifiers - ServiceNow Wiki   for further details.


This script include should be a client callable


Thanks, Ankush and Abhinay!


Adam Stout
ServiceNow Employee
ServiceNow Employee

You can get a space as a literal that is not trimmed by using the search string "javascript:' '".  You don't need a new script include just for this.

 

2025-02-27_17-41-39.png