Database View - Where Clause

Mark36
Kilo Explorer

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()

7 REPLIES 7

William Busby
Tera Guru

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'.

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. 

Ankur Bawiskar
Tera Patron
Tera Patron

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

find_real_file.png

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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