The CreatorCon Call for Content is officially open! Get started here.

Switch statement

Chuck Tomasi
Tera Patron

FWIW, I was looking for info to see if I could use a switch statement in a transform script rather than a bunch of if/else. I found no examples in the forums or wiki so I gave it a try. It worked! Here's my solution to take a single character from our HR database on a pay code (S, H, or E) and populate our own field with words.



switch (source.u_paycode.toString()) {
case 'S': target.u_paycode = "Salaried Exempt"; break;
case 'E': target.u_paycode = "Salaried Non-Exempt"; break;
case 'H': target.u_paycode = "Hourly"; break;
default: target.u_paycode = "Hourly";
}


Switch statements are an elegant solution. These work just as expected in JavaScript.

14 REPLIES 14

HA HA! That's a good one Phillip. Glad you got it figured out.


Pranav Bhagat
Kilo Sage

Hi Chuck



Can we use switch statement in jelly


Yes. It's covered in episode 1 of TechNow. Below is a partial screenshot (ignore the smart quotes PowerPoint inserted.)



TechNow Episode List



find_real_file.png


Thanks and i will go through   that .


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you