Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

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

Learn More

View all

Sign in to view all badges

Calculate end date based on drop-down list

Avatar

Avatar
Validate 1
Level 1
thaong
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
thaong
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
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)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

395 likes

Total Posts

2,686 posts

Correct Reply

491 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

395 likes

Total Posts

2,686 posts

Correct Reply

491 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
radzmar
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)
$ = Num2Date(Sum(nDate, nAddDays),"DD/MM/YYYY")

 

Answers (0)