Scheduled job for setting field value to true if two date fields values are same.

abhaysingh98
Tera Contributor

Hi guys,

 

I have created on scheduled job script for setting one field value to trueautomatically when two dates field are same, but it is not working for me.

 

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('u_current_date1', '!=', '');
ritm.addQuery('u_due_date1', '!=', '');
ritm.query();
while (ritm.next()) {
    if (ritm.u_current_date1.getDisplayValue() == ritm.u_due_date1.getDisplayValue()) {
        ritm.u_account_expiry = true;
    } else {
        ritm.u_account_expiry = false;
    }
    ritm.update();
}

 

4 REPLIES 4

Mark Manders
Mega Patron

Can you try this:

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('u_current_date1', '!=', '');
ritm.addQuery('u_due_date1', '!=', '');
ritm.query();
while (ritm.next()) {
    var currentDate = new GlideDateTime(ritm.u_current_date1.getValue());
    var dueDate = new GlideDateTime(ritm.u_due_date1.getValue());

    // Convert dates to the same format
    var currentDateValue = currentDate.getValue();
    var dueDateValue = dueDate.getValue();

    // Compare the date values
    if (currentDateValue == dueDateValue) {
        ritm.u_account_expiry = true;
    } else {
        ritm.u_account_expiry = false;
    }
    ritm.update();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders 

Its not working

Then please add logging to your script, so you can see the values that you are comparing.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders can you please guide me how to achieve that as I am new to servicenow