How to query time frame of 3 months

sarahkapasi
Giga Expert

I would like to filter a table to pull from time frame of 3 months.

Could someone please help with it?

Thank you,

Sarah

5 REPLIES 5

oharel
Kilo Sage

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


philengles
Giga Expert

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


      philip.engles@techport13.com


find_real_file.png


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.


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.