Compare field date/time with system date and time in scheduled job

Mishu
Tera Expert

To change state value to Open when custom date/time field (Reactivation Time) value matches with system date/time.

I am trying with below code, which is not giving the output.

Is there anything i am missing here ? Kindly Suggest 

 

var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('state=30^u_reactivation_timeISNOTEMPTY');
gr.query();
while (gr.next()) {

var reopen_date = new GlideDateTime(gr.u_reactivation_time);
var today_date = GlideDateTime();

if (reopen_date == today_date) {
gr.state = '10';
gr.work_notes = 'Updated State to Reopen';
gr.update();
}

1 ACCEPTED SOLUTION

@Mishu 

if you are ok with Date then use scheduled job script.

If you are ok with minutes without thinking about seconds value then use flow designer.

But running flow every minute will lead to performance issue.

Please discuss with your customer about this.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Mishu 

if you are saying dates should be same then do this

var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('state=30^u_reactivation_timeISNOTEMPTY');
gr.query();
while (gr.next()) {

var reopen_date = new GlideDateTime(gr.u_reactivation_time);
var today_date = new GlideDateTime();

if (reopen_date.getDate() == today_date.getDate()) {
gr.state = '10';
gr.work_notes = 'Updated State to Reopen';
gr.update();
}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

No, Just for Dates ..i already got that working.
I have to reopen the ticket on the exact date & time selected in the custom date/time field.
How to match the time as well ?

@Mishu 

where have you written the above script?

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

@Ankur Bawiskar ..In Scheduled Jobs