Basic Switch Statement is not working.
I'm trying to calculate the ticket that will be given based on a number in a number field. I've tried it four different ways and I can't get it to work!
FIRST WAY
switch (@Number of shifts applying for) {
case 0:
return "No Tickets";
case 1:
return "NYE";
case 2:
return "NYE + REC";
case 3:
return "3PP + C";
case 4:
return "3PP + C (Angel)";
}
SECOND
var day;
(function(){
switch (@Number of shifts applying for) {
case 0:
day = "No Tickets";
break;
case 1:
day = "NYE";
break;
case 2:
day = "NYE + REC";
break;
case 3:
day = "3PP + C";
break;
case 4:
day = "3PP + C (Angel)";
break;
}
})() ? day : day;
THREE
(@Number of shifts applying for for == 0)
? "No Tickets"
: (@Number of shifts applying for == 1)
? "NYE"
: (@Number of shifts applying for == 2)
? "NYE + REC"
: (@Number of shifts applying for == 3)
? "3PP + C"
: "3PP + C (Angel)";
FOUTH (This returns 3)
var something = "@Number of shifts applying for"
something == 0 ? "No Tickets" : something == 1 ? "NYE" : something == 2 ? "NYE + REC" : something == 3 ? "3PP + C" : "3PP + C (Angel)"

Never used "switch" in a calculation field. Your ways 3 and 4 should work, but you have typos in it.
(@Number of shifts applying for for == 0) > a "for" too muchvar something = "@Number of shifts applying for" > delete the quotation marks.
And try it in a fresh calculation field. Once a calculation has been saved, the type is fixed and can't be changed. E.g. in your 4. example the result has been 3 and if you have saved it, it's a number type calculation field now. But you need a text type.Rainer
Please sign in to leave a comment.
Comments
2 comments