Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fetching records between two dates

anil53
Kilo Contributor

Hi ,

I am trying to fetch data based on two dates  but not getting any results.

Can you update me where i am doing mistake or any option to fetch data.

where alert_bin_value and alert_app_value are alert's bin and application name.

 

var alert_created_1=gr.sys_created_on.getDisplayValue();
                                    
                                       var dateTime = new GlideDateTime(alert_created_1);
                                        dateTime.addSeconds(-1800);
                                        var modifyAlertCreatedate=dateTime;
                                             
                                   var    inc1 = new GlideRecord("incident");
                                                                                                   inc1.addEncodedQuery("assignment_group.name="+alert_bin_value+"^u_application.name="+alert_app_value+"^stateIN1,2,3^sys_created_onONLast 2 hours@javascript:gs.beginningOfLast2Hours()@javascript:gs.endOfLast2Hours()");
                                  
                                    inc1.addQuery('sys_created_on','>',modifyAlertCreatedate);
                                   inc1.addQuery('sys_created_on','<',alert_created_1);
                                    
                                  
                                    inc1.orderByDesc('sys_created_on');
                                    
                                    
                                    inc1.query();

 

 

Please help.

11 REPLIES 11

anil53
Kilo Contributor

To me,, all incident and other date values visible in my timezone which is IST. So should I use both modifyAlertCreatedate and alert_created_1 in IST time zone to use in query or have to use in GMT timezone.

or

 

what timezone have to use for below queries.

inc1.addQuery('sys_created_on','>',modifyAlertCreatedate);
                                   inc1.addQuery('sys_created_on','<',alert_created_1);

 

 

Thanks

 

Hi Anil,

To further assist you, kindly provide some more information on the actual data.

Print and share the values of these variables

modifyAlertCreatedate

alert_created_1

sys_created_on

Then add 1 condition and check if you are getting data or not.

inc1.addQuery('sys_created_on','>',modifyAlertCreatedate);

and as I understand you are using incident table. so have you created these custom fields in this table?

Also share the entire script here.