I was helping someone with a script to split dates into quarters using a When function. This code works correctly when testing it, but the popup does not return the same results. The When function is not returning the correct value in the popup.
var theDate = Date();
var theMonth = Month(theDate); //note Month is zero-based (Jan = 0)
var quarter;
//This always returns 4 in the popup, regardless of the date
//when (theMonth < 3, quarter = 1,
// theMonth < 6, quarter = 2,
// theMonth < 9, quarter = 3,
// quarter = 4}
when (theMonth < 3, quarter = 1,
theMonth < 6, quarter = 2,
theMonth < 9, quarter = 3,
theMonth < 12, quarter = 4,
quarter = "Fail");
return `Today's date: ${Text(theDate,"MMMM D, YYYY")}
Today's month: ${theMonth}
Today's quarter: ${quarter}`;
When I run the Test in the code editor, it gives me the correct result.
However, it does not in the popup.
Is this a new bug?
Solved! Go to Solution.
You have to declare the variable outside of When(). When() doesn't change any variables, it only returns a value.
var quarter = when (theMonth < 3, 1,
theMonth < 6, 2,
theMonth < 9, 3,
theMonth < 12, 4,
"Fail");
You have to declare the variable outside of When(). When() doesn't change any variables, it only returns a value.
var quarter = when (theMonth < 3, 1,
theMonth < 6, 2,
theMonth < 9, 3,
theMonth < 12, 4,
"Fail");
Thanks! It's odd that it returned the correct value in the Test, though