Posted in: ServiceNow, Undocumented

GlideFilter does work after all!?

Working with assessments I came across a piece of code that showed me that GlideFilter does support case insensitive evaluation of conditions. Up until now I was under the impression that GlideFilter is not fully functional in that it can’t do just that. ServiceNow Guru Tim Woodruff nicely details and demonstrates how the known usage pattern does not work to do case insensitive condition evaluation. I encourage you to read his article.

The Script Include that brought light into the dawn is the one called AssessmentUtils. It reveals that GlideFilter also has a constructor and using it allows evaluating conditions in a case insensitive manner. Actually it turns out other Script Includes are also using GlideFilter in this way.

Enough talk let’s see some code:

var id = '00000000000000000000000000000000',
    current = new global.GlideRecordUtil().getGR('task', id),
    doesRecordMatch,
    condition = 'active=true^numberMATCH_RGXinc.+123',
    gf = new GlideFilter(condition, '');

gf.setCaseSensitive(false);
doesRecordMatch = gf.match(current, true);
gs.debug(doesRecordMatch);

Running the script above in Scripts – Background prints out:


*** Script: [DEBUG] true


Of course you will have entered a valid sys_id instead of the all 0 one and that is that of an incident who’s number ends in 123. Yes, it supports RegExp too.

Commenting out line

gf.setCaseSensitive(false);

and executing the script again prints out:


*** Script: [DEBUG] false


The key here was to use the GlideFilter constructor with two parameters (the first being the condition to evaluate and the second one is a mystery to me) and using the setCaseSensitive method of the returned object. Note that the method executing the check is now called match.

As a last word, I’d caution you that as far as I know this is not a documented usage, so while it works right now, it might not work later, also the results are not guarantied and you shall use this on your own risk.

Leave a Reply