Auto-populate Expiration date based on the Start date and Duration of months selected

Nagashree5
Tera Contributor

Hi All,

 

Below are the fields on the form level.

Nagashree5_0-1697640605501.png

Based on the start date and duration of months selected (it is a dropdown of 1 to 12 numbers) - Expiration date should be auto populated.

suppose if the start date is selected as 10-18-2023 and duration of months is selected as 3 months, the Expiration date needs to be auto populated as 10-18-2023 + 90 days.

Can anyone guide me on this.

 

TIA.

15 REPLIES 15

Hi @Alka_Chaudhary,

 

The answer is returning null when i kept log and checked in client script. Can you please suggest.

Hello @Nagashree5 ,

Please provide the screen shot of Client script and script include.

Also, provide the backend names of the following variables-

  • POA Start Date
  • POA Duration (in months) and choice value of this field. 
  • POA Expiration Date

Thanks,

Alka

Hi @Alka_Chaudhary,

  • POA Start Date - poa_start_date
  • POA Duration (in months) and choice value of this field. - poa_duration_in_months
  • POA Expiration Date - poa_expiration_date

Client Script:

Nagashree5_0-1697771049325.png

Script Include:

Nagashree5_1-1697771159626.pngNagashree5_2-1697771182858.png

 

Hello @Nagashree5 ,

Also provide the choices value of variable 'POA Duration (in months) '.

I will provide you the updated the script.

Thanks,

Alka

Vanderlei
Mega Sage

Hi @Alka_Chaudhary @Nagashree5 , try the code below(Client Script Only)

This code uses only Javascript Date API to add Months to a Date

 

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

var date_number = getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format);
var my_date = new Date(date_number)

my_date.setMonth(my_date.getMonth() + 1 + newValue)

g_form.setValue("your_field",my_date.toLocaleDateString())

}

 

If my answer helped you, please mark my answer as helpful.

 

Vanderlei Catione Junior | LinkedIn

Senior ServicePortal Developer / TechLead at The Cloud People