Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## Calculate end date based on drop-down list

thaong
Level 1

Likes

0 likes

Total Posts

7 posts

1 solution
View profile

thaong
Level 1

Likes

0 likes

Total Posts

7 posts

1 solution
View profile
thaong
Level 1

28-03-2020

I have a drop-down list with 8 different programs that the company is delivering and 2 date/ time fields called StartDate and EndDate. Depending on what is selected from the drop-down list, the EndDate is calculated accordingly. I have the scripts here but it doesn't seem to work. Can you help me point out where I got wrong please? Many thanks

form1.#subform[0].StartDate::exit - (FormCalc, client)

var date = Date2Num(StartDate.formattedValue,"DD/MM/YYYY")
var value = Programs.boundItem(xfa.event.newText)
if (value == "1") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "2") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "3") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "4") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "5") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "6") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "7") then
EndDate.formattedValue = Num2Date(date + 639,"DD/MM/YYYY") else

if (value == "8") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY")

endif

#### Accepted Solutions (1)

MVP

Likes

395 likes

Total Posts

2,686 posts

491 solutions
View profile

MVP

Likes

395 likes

Total Posts

2,686 posts

491 solutions
View profile
MVP

28-03-2020

The formattedValue is defined by a display pattern. You can't set it via scripting.

And never use reserved names such as "value" or "date" for variables, this can cause unexpected results.

Here's a much shorter FormCalc script you can put into the calculate event of the EndDate field.

``````var nDate = Date2Num(StartDate.formattedValue,"DD/MM/YYYY")
var nSelection = Programs
var nAddDays = Choose(nSelection, 548, 457, 548, 457)