Date filter using script include

anil53
Kilo Contributor

Hi All,

To fetch incident records using schedule job, I have to apply date filter in script include.

i have query regarding this filter.

1. As snow db store data in GMT format , so in which format date field value should be applied as filter?

I think whenever we use INCIDENT UI Form to filter records based on creation date, we apply filter based on user's time zone which use to internally converted to GMT format.

So when we use script include, so should we write code to directly apply filter as per user's time zone or should we apply filter in GMT time zone on incident table ?

 

For Example :--

If i have to filter incident records from 7 july 2018 to 10 july 2019, what should we the correct syntax.

 

 

Please support.

 

 

6 REPLIES 6

Ankur Sharma
Tera Guru

Hi Anil,

Please find the script below if you need to filter incidents created between 07 July 2018 to 10th July 2019.

var grInc = new GlideRecord("incident");

grInc.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2018-07-07','00:00:00')@javascript:gs.dateGenerate('2018-07-10','23:59:59')");

grInc.query();

 

Let me know if it helps.

I want to fetch record from incident table greater than 10.00 AM and less than 5.00 PM on July 10,2018 of creation date then what will the query?
Or
If I fetch incident record after  alert creation date and before some other alert creation date, then what would be the query?

anil53
Kilo Contributor

Hi ,

I want to fetch record from incident table greater than 10.00 AM and less than 5.00 PM on July 10,2018 of creation date then what will the query?
Or
If I fetch incident record after  alert creation date and before some other alert creation date, then what would be the query?

Try the following:

var grInc = new GlideRecord("incident");

grInc.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2018-07-10','10:00:00')@javascript:gs.dateGenerate('2018-07-10','17:00:00')");

grInc.query();

 

Let me know if it helps.