DOES NOT START WITH filter

Anish Reghu
Kilo Sage

Dear all,

This was asked 5 years ago, unanswered. Asking it again to a much wider audience now, hopefully.

Can someone suggest that script include for DOES NOT START WITH and how to call that from a advanced filter? Please don't refer me to threads, even the thread marked as RESOLVED does not have the solution in it. Any help is appreciated.

I know one solution is to create a advanced filter and calling a script include. But I would need the solution instead of the approach.

Any answers?

 

Regards,

Anish

1 ACCEPTED SOLUTION

Filip Vojt__ek
Giga Guru

Hi Anish,

 

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

 

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

gr.addQuery('name', 'NOT LIKE', 'StartString%');

 

Pls mark as helpful if solution works.

View solution in original post

21 REPLIES 21

DirkRedeker
Mega Sage

Hi

I just have a proposal of how you could simulate this scenario.

You can "exclude" certain "ranges" of values, by having TWO  "BETWEEN" conditions "ORed" together.

See the next screenshot for an example:

find_real_file.png

In this example, I use the field "Info" on a custom table, which is a String type field.

I have TWO ranges for the condition; both with BETWEEN:

The first range has all values between "a" and "IB"...

Then i "Exclude" everything starting with "IC" by starting the next range at "ID" and ends "open".

This will exclude all Records starting with "IC", but also the ones with "IBa", "IBc" and so on.

If you want to include also "IBa", "IBb", etc, just run the first range up to "IBz" for example.

This way, you can simulate something like "DOES NOT START WITH".

This is just a workaround, but as there is no such OOB function, this at least helps somewhat.

 

Let me know, if that answers your question and mark my answer as correct and helpful.

Enjoy & BR

Dirk

This is a neat manipulation to produce the desired result.

I came here looking for a solution for filtering the Subject on sys_email table and this works brilliantly until I start hitting special characters.  For instance, I'm not sure if a { is less than or greater than a ~.  I was thinking it could be ascii valued, but the ServiceNow filter seems to be case insensitive.

So turns out it wasn't so hard to figure out what the order is for special characters.  I just created a new table, added a string field (non UTF-8) and added all the special characters to the tables.  Then if you open the table, you can sort the records.  Below is the sort order of the special characters from first to last (lowest to highest).  I only added one letter into the results below, just to show how the instance was sorting letters versus the special characters.  You can test your own filters against the list.  Seemed to be working in my own tests.

 

!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
[
\
]
^
_
`
{
|
}
~

Thanks Dirk, this is exactly what I was needing in my scenario. I needed entries that do not start with "DV".

The accepted "gr.addQuery('name', 'NOT LIKE', 'DV%');" solution, though more polished in appearance, simply did not work for me; it apparently produced an invalid query, as I began returning all records. I would have preferred using that one had it worked, but I'm glad to have your solution! Thanks!

Anish Reghu
Kilo Sage

Thanks all, but what I was exactly looking for is that I need "DOES NOT START WITH" to be shown as a operator in the list filter. And I want that filter to do the job.

The solution by @hammad ul aziz is not dynamic since you glide into the incident record and if I want to use this filter on a different table - I have to change the code. But of course, thanks for taking time and respond. This will definitely help in some other context.

The solution by @Brad Bowman seems to be the one I am looking for, but Brad I would want "does not start with" to be shown on the filter instead, not embedded into any field at the Dictionary level in the reference qualifier. Can you help further.

Extremely thankful for the responses here and I apologize for responding late on this thread.