Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with Encoded query in flow designer

Snowman15
Giga Guru

Hi everyone,

I'm working on a Flow Designer script in ServiceNow where I build an encoded query to filter records. One of the conditions I need is to exclude any records on the sys_email table where the recipients field  contains @hotmail 

I’ve tried the following variations but none of these seem to work:

 

If I remove that condition, flow works correctly. Any idea what's happening?

Here is the full script:

 

var gdt = new GlideDateTime();


var ms = 65 * 60 * 1000; // 65 minutes in milliseconds

gdt.add(-ms); // subtract 65 minutes

 var encodedQuery = [

'u_accountISEMPTY',  

'mailbox=sent',  

'sys_created_on>=' + gdt.getValue(),  

'target_tableSTARTSWITHsn_customerservice',  

'target_tableENDSWITHcase',

'recipientsNOT LIKE@hotmail'

].join('^');

return encodedQuery;
 
Snowman15_0-1760978287686.png

 

1 ACCEPTED SOLUTION

Snowman15
Giga Guru

Hi @Ankur Bawiskar  that didn't work either, for some reason when adding that condition, the look up always returns 0 results. I have now found a workaround to filter those records out by adding a step after that, not ideal but did the job. Thanks all.

View solution in original post

9 REPLIES 9

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Snowman15 

Can you check the below code ?

var gdt = new GlideDateTime();
var ms = 65 * 60 * 1000; // 65 minutes in milliseconds
gdt.add(-ms); // subtract 65 minutes

var encodedQuery = [
'u_accountISEMPTY',
'mailbox=sent',
'sys_created_on>=' + gdt.getValue(),
'target_tableSTARTSWITHsn_customerservice',
'target_tableENDSWITHcase',
'recipients!LIKE@hotmail'
].join('^');

return encodedQuery;

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@Ravi Gaurav that didn't work but thanks

Ankur Bawiskar
Tera Patron
Tera Patron

@Snowman15 

it works fine here so it should work there as well

Did you hard-code that encodedquery in background script and see if that works?

AnkurBawiskar_0-1761050456749.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Snowman15 
try this once -> use wild card along with NOT LIKE operator

var gdt = new GlideDateTime();
var ms = 65 * 60 * 1000; // 65 minutes in milliseconds
gdt.add(-ms); // subtract 65 minutes

var encodedQuery = [
'u_accountISEMPTY',
'mailbox=sent',
'sys_created_on>=' + gdt.getValue(),
'target_tableSTARTSWITHsn_customerservice',
'target_tableENDSWITHcase',
'recipientsNOT LIKE%@hotmail%'
].join('^');

return encodedQuery;

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Snowman15
Giga Guru

Hi @Ankur Bawiskar  that didn't work either, for some reason when adding that condition, the look up always returns 0 results. I have now found a workaround to filter those records out by adding a step after that, not ideal but did the job. Thanks all.