Script to carry date from one variable to another

Darlene York
Tera Contributor

Hello,

 

I am trying to do a script that says if the audit source is external then carry over the requested completion date over to the negotiated completion date.  But my script is not working.

 

Any assistance is appreciated.

 

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

    // Check if the audit_source value is "External"
    if (newValue == 'External') {
        var requested_completion_date = g_form.getValue('requested_completion_date');
        if (requested_completion_date) {
            g_form.setValue('negotiated_completion_date', requested_completion_date);
        }
    }
}
 
DarleneYork_0-1746116603816.png

 

1 ACCEPTED SOLUTION

AbinC
Tera Contributor

Hi @Darlene York ,

 

Try:

var start_date = getDateFromFormat(newValue, g_user_date_format);
start_date.addDays(-3);
g_form.setValue('the_other_date_field', start_date);

So with this, you can use an onChange client script, choose the field as the start date, then just change "the_other_date_field" to the name of the other date field and it should do the rest. 

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
Abin

View solution in original post

2 REPLIES 2

AbinC
Tera Contributor

Hi @Darlene York ,

 

Try:

var start_date = getDateFromFormat(newValue, g_user_date_format);
start_date.addDays(-3);
g_form.setValue('the_other_date_field', start_date);

So with this, you can use an onChange client script, choose the field as the start date, then just change "the_other_date_field" to the name of the other date field and it should do the rest. 

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
Abin

Thank you for the quick reply!  I appreciate it.  Have a nice day!