should populate date time field in catalog varialbe

suresh kaliappa
Tera Expert

Hello , 

 

My new requirement was in a catalog item i created new field called expected date. it selects future dates. There is another read only field called lead time. The purpose of the field is to subtract the expected start with current date and needs to populate in lead time field. 

 

Ex. when user selected expected days  after 2 days from the date of submitting then the lead time should count the number of days and hours left to expected start. So can someone please suggest how this can be achieved? any help will be great helpful. 

1 REPLY 1

Mark Manders
Mega Patron

Something like this could help, depending on your field types, but you can use it as a base to create your own script:

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

    // Parse the future date
    var futureDate = new GlideDateTime(newValue);
    // Get the current date and time
    var now = new GlideDateTime();

    // Calculate the difference in days
    var diff = futureDate.getNumericValue() - now.getNumericValue();
    // Convert the difference from milliseconds to days
    var daysUntil = Math.ceil(diff / (1000 * 60 * 60 * 24));

    // Set the 'days_until' variable with the calculated days
    g_form.setValue('lead_time', daysUntil);
}

 


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