Date population based on the end date

Not applicable

Need suggestion on one script, 

 

Based on the option selection need to set the end date from the start date. 

Choices - 1 day, 1 week, 1 month. 

if 1 week is selected, then based on the start date need to set the date in the end date field. 

tried the below script. 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    // Type: onChange
    // Field: duration_choice
    // Description: Set the end date based on the duration choice field

    if (isLoading || newValue === '') {
        return;
    }
var currentDate = new Date();
    var endDate = new Date(currentDate);

var nest = g_form.getValue('date');

if (nest == '1 day' && newValue){
endDate.setDate(currentDate.getDate() + 1);
} else if( nest == '1 week'){
    endDate.setDate(currentDate.getDate() + 7);
} else if( nest == '1 month'){
    endDate.setMonth(currentDate.getMonth() + 1);
}
var user_date = formatDate(new Date(endDate), g_user_date_format);

    g_form.setValue('select_date', user_date);
}
 
 
its not working properly. need suggestions. 
1 REPLY 1

Not applicable

Hi @Community Alums ,

Can you provide a screenshot or explanation of what error are you having when you execute this code. That will help me to troubleshoot.