How to query time frame of 3 months
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2016 01:09 PM
I would like to filter a table to pull from time frame of 3 months.
Could someone please help with it?
Thank you,
Sarah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2016 01:20 PM
Hi Sarah,
Say you want all open incidents from the last 3 month.
In your BR (depends on where you're filtering or what you're trying to do), add the following:
var encQuery = 'active=true^opened_at>=javascript:gs.monthsAgoStart(3)'
var inc = new GlideRecord('incident');
inc.addEncodedQuery(encQuery);
inc.query();
etc...
If you provide more info, perhaps I can help with the code even more.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2016 01:33 PM
Hey Sarah,
This is a similar post: GlideRecord query against glide_date_time field
Take aways are that the sys_created_on exists on every table. So you can query against that column, also depending on when you need to query against in relation to the how many months you need to go back, I would look into: GlideDateTime - ServiceNow Wiki
There is an addDays() function and a subtract() function that should point you in the right direction of getting the date range that you are looking for.
Best Regards,
Philip Engles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 09:45 AM
Thank you for your help. We are actually doing this on a client script and not business rule. Would you happen to know what I would need to add on the client script?
Thanks again for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 10:36 AM
Hi Sarah,
Since you are doing this in a client script, your client script will have to a call a script include to do this server side functionality via GlideAjax. Then your will have to parse out that response in your client script. If that does not make much sense, please look into this blog post and report back with any questions that you have. SN Pro Tips — GlideRecord & GlideAjax: Client-Side Vs. Server-Side
Best,
Philip E.