The CreatorCon Call for Content is officially open! Get started here.

Not able to generate query for date

Ashutosh35
Kilo Contributor

Need help for generating an encoded query. 

 

The query which I generated from filter  is 
"requested_for=8cc54160dbd82f4061ca8d37489619e2^state=3^startON2020-08-17@javascript:gs.dateGenerate('2020-08-17','start')@javascript:gs.dateGenerate('2020-08-17','end')"

var requester = "8cc54160dbd82f4061ca8d37489619e2";

var dateCheck = "2020-08-17";

Need help in creating a query where I need to replace the bold items with requester and dateCheck. 

 

Tried this in background script but always getting the error. The part where I am getting error is in the second and third bold dates. Error - Unexpected token start

var requestor = '8cc54160dbd82f4061ca8d37489619e2'; //sysID of the user
var datecheck = '2020-08-18'; //Date to put
var gr = new GlideRecord("sn_wsd_core_workplace_request"); //Query the table
gr.addEncodedQuery("requested_for="+requestor+"^state=3^startON"+datecheck+"@javascript:gs.dateGenerate("+datecheck+","start")@javascript:gs.dateGenerate('2020-08-17','end')");
gr.query();

while(gr.next()){
gs.print("test");
}
gs.print(gr.getRowCount());

 

 

 

2 REPLIES 2

Tony Chatfield1
Kilo Patron
Hi, I don'y think the quotes around +datecheck+ are necessary and effectively make it a string. Try creating a variable and include spacing so you can see clearly and log to review. Replying fron my phone but something like; var theQuery = "requested_for=" + requestor + "^state=3^startON" + datecheck + "@javascript:gs.dateGenerate(" + datecheck + ",'start')@javascript:gs.dateGenerate('2020-08-17','end')"; gr.addEncodeQuery(theQuery);

Jaspal Singh
Mega Patron
Mega Patron

Hi Ashutosh,

 

Issue with quotes. Can you try replacing

gr.addEncodedQuery("requested_for="+requestor+"^state=3^startON"+datecheck+"@javascript:gs.dateGenerate("+datecheck+","start")@javascript:gs.dateGenerate('2020-08-17','end')");

with

gr.addEncodedQuery("requested_for="+requestor+"^state=3^startON"+datecheck+"@javascript:gs.dateGenerate("+datecheck+",'start')@javascript:gs.dateGenerate('2020-08-17','end')");