Due Date Field GlideDateTime comparison

Anubhav24
Mega Sage
Mega Sage

Hi All,

 

We have a field Due Date on catalog task form and I have to compare the old and new values on change of due date field in a onChange Client Script.

I am simply getting the value using g_form and then doing the equal to check , do I need to convert these dates or a simple comparison is fine.

 

Thanks in advance.

8 REPLIES 8

@Anubhav24 

we usually add that comparison so that the onChange does the validation or it triggers only when the value actually changes and doesn't trigger unnecessarily.

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

@Anubhav24 

Thank you for marking my response as helpful.

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

@Anubhav24 

Hope you are doing good.

Did my reply answer your question?

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

Shubham_Jain
Mega Sage

@Anubhav24 See if this helps you --

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == oldValue) {
        return;
    }

    var oldDate = new Date(oldValue);
    var newDate = new Date(newValue);

    if (newDate.getTime() !== oldDate.getTime()) {
        g_form.addInfoMessage("Due Date has changed.");
    }
}

 

 

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain