Needs to update the form on change of some fields

temp07
Giga Contributor

This is the script I am using in client script:

 

(function() {
    // Get the start date, end date, and the field value
    var startDate = g_form.getValue('fth_startdate');
    var endDate = g_form.getValue('fth_enddate');
    var fieldValue = g_form.getValue('fth_country');

    // If both start date, end date, and field value are provided
    if(startDate && endDate && fieldValue) {
        // Convert start date and end date strings to Date objects
        var startDateObj = new Date(startDate);
        var endDateObj = new Date(endDate);

        // Calculate the difference in milliseconds
        var timeDifference = endDateObj.getTime() - startDateObj.getTime();

        // Convert milliseconds to days
        var daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));

        // Multiply days by appropriate factor based on field value
        var multiplier = 1;
        if (fieldValue === 'a') {
            multiplier = 14;
        } else if (fieldValue === 'b') {
            multiplier = 16;
        }
        var multipliedDays = daysDifference * multiplier;

        // Set the calculated days value to a field on the form
        g_form.setValue('calculated_field', multipliedDays);
    } else {
        // If either start date, end date, or field value is not provided, clear the days field
        g_form.setValue('calculated_field', '');
    }
})();
1 REPLY 1

Bert_c1
Kilo Patron

What is the 'Type' value on your client script? Provide more details and someone here may assist.

 

Have a look at:  tips-on-asking-question-on-community

 

And state what is the problem with your script.