Database View - Where Clause
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 05:07 PM
Does anyone know the script to filter on records created 90 days or 3 months ago within the Where Clause of a Table within a Database View?
Below is the javascript command I have applied but this does not work. Note 'sa_timestamp' is the field that displays the date I want to filter on.
sa_timestamp>=javascript:gs.beginningOfLast90Days()
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 09:43 PM
This should be pretty simple. Have you tried going to the list view of the table and creating a filter using the 'Relative' operator? I did a quick one on the incident table to list records created older than the last quarter but you can use any time frame as a reference. Once you have the query defined in the list view you can right click on the query string to copy the query to the clipboard to insert into your script with the 'addEncodedQuery' GlideRecord operator. My query was defined with the encoded query string of 'opened_atRELATIVELE@quarter@ago@1' but you may prefer the query string of 'opened_atRELATIVELE@dayofweek@ago@90'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 10:58 AM
Thank you for your response William. I applied the code above in the Where Clause but to no a avail. I received an error message each time I tested (clicked on 'Try It') that this script was not understood.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 11:44 PM
Hi Mark,
Why not create a report instead of Database view
screenshot below with the condition; you can use your own field instead of created on
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 10:56 AM
Thank you for response Ankur. Based on the parameters I established for the database join, the code has to feature within the Where Clause within the Database View