- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 08:06 AM
Hi All,
I am running following query in backgroud script to validate if Encoded query takes date field. I formed this query using list filter -> copy query but its not working. Any suggestion how between operator to enter in encoded query string.
My code:
var tableData = new GlideRecord('incident');
tableData.addEncodedQuery('sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2');
tableData.query();
gs.addInfoMessage("Count: " +tableData.getRowCount());
I am getting this error:
Output:
Javascript compiler exception: missing ) after argument list (<refname>; line 2) in:
var tableData = new GlideRecord('incident');
tableData.addEncodedQuery('sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2');
tableData.query();
gs.addInfoMessage("Count: " +tableData.getRowCount());
Thanks in Advance.
Regards,
Prasad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 10:28 AM
Prasad,
You've gotten the answer to your issue, but here my attempt to explain the why it works. Your issue had to do with the single-quote as part of the date specification:
sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)
You wrapped the input to the addEndcodedQuery function in single quotes like this: addEncodedQuery('sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2')
The function had trouble parsing the input because Javascript would break that apart by items encapsulated between the single-quotes which would break down like this:
input1: sys_created_onBETWEENjavascript:gs.dateGenerate( // String used as query but would fail due to incompleteness of the query, which aligns with the error you were seeing
input2: 2015-10-07 // only Ints and vars can be passed this way, so the string would have caused an error, discarded because unexpected input
input3: , // String but no handler because addEncodedQuery is looking for a single input, discarded because unexpected input
input4: 00:00:00 // only Ints and vars can be passed this way, so the string would have caused an error, discarded because unexpected input
input5: )@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2 // String but no handler because addEncodedQuery is looking for a single input, discarded because unexpected input
All because Javascript tried to break the inputs into chunks using the single-quote delimiter. By using double quotes to wrap the string you get the single input you were looking to pass to the addEncodedQuery function: addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2")
input1: sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2
Hope that helps your understanding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 08:15 AM
Query needs to be in double quotes.
tableData.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2");
Thanks,
Malaya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 08:28 AM
Thanks Malaya. I have tested with 99 other queries and they worked fine with single quotes. Do you know the reason why only BETWEEN dosen't work with single quotes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 09:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 08:31 AM
I suspect it's you're quoting in line 3.
Build your encodedQuery seperate from the addEncodedQuery:
var myQuery = "sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2";
tableData.addEncodedQuery(myQuery);