How to compare the date between GlideDate and GlidedateTime fields in an Onchange client script

Madhan007
Tera Contributor

Hi all , 
In a Form , I got  Submissiojn Date & Time field (glide_date_time) and SLA Date (glide_date) fields. I am trying to write an onchange client script on SLA Date field  to check if the entered SLA Date is greater than Submission Date and if not clear the SLA field value.

I am trying to convert the glide_date_time object (Submissiojn Date & Time field) to glide_date and compare with glide_date object (SLA field) with the below code. 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var dateTime = g_form.getValue('issue_submission_date');  //glideDateTime 
    var date = g_form.getValue('extended_sla');                        //glideDate
    var issueSubmissionDate = new Date(dateTime);      //converting glidedatetime into a date object
    var extendedSLA = new Date(date);                            
    alert("sub date-" + issueSubmissionDate);
    alert("extended sla" + extendedSLA);

}
 
But the alert for issue submission date says invalid .

how can I achieve it ? Please pour you Insights

Thanks in  advance!!
2 REPLIES 2

Zach Koch
Giga Sage
Giga Sage

All GlideDate and GlideDateTime methods are server side. You won't be able to use them client side and will need a GlideAjax and script include to use them.

 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Brian Lancaster
Tera Sage

There are two ways to do this.

Option 1: No Code date validation UI Policy

Option 2: Script Include Call