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.

Encoded query not working

Ekta Sharma
Tera Contributor

Hi. My below encoded query is not working

 

taskGr.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate" + (dat));

I am passing data as parameter in API and its value is being sent as ( with single quotes) : '2025-01-08','00:00:00'

Can you pls help with the encoded query. 
2 REPLIES 2

priyatam_pvp
Tera Guru

Try the code below

taskGr.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate('" + dat + "')");

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Priyatam

ZacharyKenyon
Kilo Guru

I am seeing two potential issues here:

 

  • You're using ":" between "javascript" and "gs.dateGenerate" - that does not work in my testing (in background scripts);  you should use an actual colon
    • edit: looks like the community site automatically changes a colon to :
  • You don't have the parentheses for gs.dateGenerate in the string for the encoded query


    This should work:
    var date = "'2025-01-08','00:00:00'";  // string (doublequotes) enclosing two string parameters (in single quotes)

    taskGr.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate(" + date + ")"); // use an actual colon instead of :

 

documentation for gs.dateGenerate:  https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/...