Not able to pass date and time query params in scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2019 12:37 PM
Hello everyone,
I am trying to pass a date and time value on a glide record for incident table to get incidents that are created after particular time. Here is the code that I have been trying,
var timeDuration;
timeDuration = request.queryParams.duration;
var gr= new GlideRecord("incident");
gr.addQuery("sys_id","incident.sys_id");
gr.addEncodedQuery('sys_created_on>=javascript:gs.dateGenerate(timeDuration)');
gr.query();
while(gr.next()){
}
Note: duration is the query parm that I have created on the API.
I have put a log for "timeDuration" whether the passed value from the REST API explorer is getting to it, it is working fine. But I could some error saying so,
org.mozilla.javascript.EcmaError: "timeDuration" is not defined.
Caused by error in sys_ws_operation.c166b7d3db97a748e312748e0f9619f5.operation_script at line 1
==> 1: gs.dateGenerate(timeDuration)
Can anyone help me with it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2019 02:15 PM
Hi, gs.dateGenerate shows parameter 'timeDuration[i]' but I don't see anywhere where i is set.
So I think you are implying timeDuration is an array, but don't identify which value should be utilized from within the array .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2019 06:48 AM
Hi Tony,
That's not an array. It was a mistake. Sorry for misleading. It's just a variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2019 03:17 PM
If input is a single value, try the below script
var timeDuration = request.queryParams.duration; //'2019-02-06,00:00:00';
var query = 'sys_created_on>=' + timeDuration;
var gr= new GlideRecord("incident");
gr.addEncodedQuery(query);
gr.query();
while(gr.next()){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2019 07:39 AM
Hi,
Thanks for the response. It worked for me, but the the response I am getting is being converted to GMT, even though I am in EST.
The record in my system shows a different time from the response. can you help me with it?
Thanks,
Murali