how to create dynamic encoded query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 10:51 AM
Hi ,
Goal: to calculate incident opened in each month until the current month
Question: Can i use a dynamic placeholder( date ) in gs.dateGenerate() method.
Details: I am trying to use gs.dateGenerate(placeholder for a date value) by supplying the argument dynamically. I am trying to construct a date with gs.monthsAgoStart and gs.monthsagoEnd . something like this....
1> var startDate = gs.monthsAgoStart(7);
2> var endDate = gs.monthsAgoEnd(7);
3> var encodedQuery = "active=true^sys_created_onBETWEENjavascript:gs.dateGenerate(startDate)@javascript:gs.dateGenerate(endDate)";
4> var gr = new GlideRecord('incident');
5> gr.addEncodedQuery(encodedQuery);
6> gr.query();
On line 3 when i try and plug the variable startDate and endDate the query does not run. If is use gs.monthsAgoStart() directly it works. However my need is that I use a variable something like this....
for(int i=0;i<8;i++){
1> var startDate = gs.monthsAgoStart(i);
2> var endDate = gs.monthsAgoEnd(i);
3> var encodedQuery = "active=true^sys_created_onBETWEENjavascript:gs.dateGenerate(startDate)@javascript:gs.dateGenerate(endDate)";
4> var gr = new GlideRecord('incident');
5> gr.addEncodedQuery(encodedQuery);
6> gr.query(); }
observe the i counter in monthsAgoStart() and monthAgoEnd() to calculate incident in different months.
Any suggestions.help. Appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 10:58 AM
havent tried this, but try something like ...
var encodedQuery = "active=true^sys_created_onBETWEENjavascript:gs.dateGenerate(" + startDate + ")@javascript:gs.dateGenerate(" + endDate + ")";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 11:37 AM
Hi Chris,
Thanks for reply. Actually I found the issue...when you use gs.monthsAgosStart or any date time related funtion it is internally using gs.dateGenerate and I was again using the same in my encodedQuery,which is wrong. I tried this active=true^sys_created_onBETWEEN"+startDate+"@"+endDate; and it worked. Thanks to Abhishek Rakshe.