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

Tony Chatfield1
Kilo Patron

Hi, have you debugged\printed your result to screens in order to see whats going on

I see the first line list here var alert_created_1=gr.sys_created_on.getDisplayValue();
But don't see gr defined anywhere, is there an initial line of script where gr is defined IE var gr = new GlideRecord (of some sort)?

 

This is alerday defined in starting of code.

 

var gr = new GlideRecord ('em_alert)

 

We are fetching some open alerts which has no incident copied only . and for each alerts i want to fetch incident.

 

Please check and help to identify where is miss as no data is coming.

anil53
Kilo Contributor

This is alerday defined in starting of code.

 

var gr = new GlideRecord ('em_alert)

 

We are fetching some open alerts which has no incident copied only . and for each alerts i want to fetch incident.

 

Please check and help to identify where is miss as no data is coming.

 

Hi Anil,

I suggest you print the values of these variables alert_bin_value, alert_app_value,modifyAlertCreatedate,alert_created_1 and run this in background once with static values and see if you are getting any data.

Most probably one of the variables below might not be matching the condition.

Mark the answer as correct/helpful if you find this helpful