# Functions CASE() or SWITCH() Not Working

**URL:** <https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617>\
**Category:** Ignition\
**Created:** [December 11, 2019, 6:32pm UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617 "2019-12-11T18:32:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![acast329](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@acast329](https://forum.inductiveautomation.com/u/acast329)\
**Post date:** [December 11, 2019, 6:32pm UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/1 "2019-12-11T18:32:43Z")

</div>

When I try to run in script console the sample that is showed in the web site [https://docs.inductiveautomation.com/display/DOC80/case](https://docs.inductiveautomation.com/display/DOC80/case)

case(  
1, #// value  
0, #// case 1  
“Off”, #// return 1  
1, #// case 2  
“Running”, #// return 2  
2, #// case 3  
“Fault”, #// return 3  
forceQuality("!BAD STATE!",0)) #// default

I got this error  
Traceback (most recent call last):  
File “”, line 1, in   
NameError: name ‘case’ is not defined

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 11, 2019, 6:34pm UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/2 "2019-12-11T18:34:20Z")

</div>

These are expression language functions, you can’t use them in scripting.

---

<div class="post-metadata">

**Author:** ![acast329](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@acast329](https://forum.inductiveautomation.com/u/acast329)\
**Post date:** [December 11, 2019, 6:43pm UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/3 "2019-12-11T18:43:02Z")

</div>

There is another function like case that I can use in scripting?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 11, 2019, 6:55pm UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/4 "2019-12-11T18:55:31Z")

</div>

The “pythonic” way to do that is define a dictionary as if a constant (outside your script function if in a script module), with the lookup values as keys and the results as the corresponding content. Then you just `return myCasesDictionary[myKeyToLookUp]`.

If the cases are more dynamic than that, use python’s `if...elif...elif...else` construct.

---

<div class="post-metadata">

**Author:** ![NII](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nii/32/12920_2.png) [@NII](https://forum.inductiveautomation.com/u/NII)\
**Post date:** [February 4, 2020, 4:08am UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/5 "2020-02-04T04:08:19Z")

</div>

Cay you elaborate ‘expression language functions’ ?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 4, 2020, 5:12am UTC](https://forum.inductiveautomation.com/t/functions-case-or-switch-not-working/30617/6 "2020-02-04T05:12:25Z")

</div>

See [Expression Functions](https://docs.inductiveautomation.com/display/DOC79/Expression+Functions) in manual–there’s also a link near the top of that page to read more about expressions–vs. [Scripting](https://docs.inductiveautomation.com/display/DOC79/Scripting).
