JavaScript Assistance Required - Syntax error missing before statement
Copy link to clipboard
Copied
I am getting this syntax error, "SyntaxError: missing ; before statement 1: at line 2."
Here is the code I have:
var P&ADate = this.getField("P&ADate").valueAsString;
if (P&ADate=="") event.value = "";
else (
var date = util.scand("mm/dd/yyyy", P&ADate);
var addTime = this.getField("AddTime").value;
var days = 0;
if (addTime != "Off") (
switch (addTime) (
case "45days" :
days = 44;
break;
)
date.setDate(date.getDate()+days);
event.value = util.printd("mm/dd/yyyy", date);
)
else (
event.value = "";
)
)
The goal is when the checkbox is selected, a date of 45 days will be calculated and populated. The 45 days is based on an initial request date appearing in a calendar field.
For example, my initial request is 10/4/2024. I check the P&ADate box. A date of 11/18/2024 is displayed.
Any assistance is greatly appreciated.
Copy link to clipboard
Copied
Don't use & in the name of the variable.
Copy link to clipboard
Copied
Also, this part is unnecessarily convoluted:
if (addTime != "Off") (
switch (addTime) (
case "45days" :
days = 44;
break;
)
You can replace it with this:
if (addTime=="45days") days = 44;

