# Expression not returning expected valuebut only for ON and OFF keyword

**URL:** <https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794>\
**Category:** Ignition\
**Created:** [June 13, 2024, 3:28am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794 "2024-06-13T03:28:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sum\_dun](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@sum\_dun](https://forum.inductiveautomation.com/u/sum_dun)\
**Post date:** [June 13, 2024, 3:28am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/1 "2024-06-13T03:28:23Z")

</div>

I have an expression if({PLCTAG/M24\_MF}, "ON", "OFF") and instead of ON and OFF it returns me 1 and 0 respectively. I tried ONN and OFFF in expression  
if({PLCTAG/M24\_MF}, "ONN", "OFFF") and it works as intended returning me ONN or OFFF. Only ON and OFF does not work other all string works.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 13, 2024, 7:30am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/2 "2024-06-13T07:30:51Z")

</div>

Welcome to the forum.  
Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 13, 2024, 7:40am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/3 "2024-06-13T07:40:00Z")

</div>

I am unable to reproduce the problem on 8.1.41.

I have an expression tag bound to `myBool` (a boolean tag).  
`if({[default]myBool}, "ON", "OFF")`

It works as expected.

What is the data type of `M24_MF`?

---

<div class="post-metadata">

**Author:** ![sum\_dun](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@sum\_dun](https://forum.inductiveautomation.com/u/sum_dun)\
**Post date:** [June 13, 2024, 8:31am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/4 "2024-06-13T08:31:11Z")

</div>

It's a boolean.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 13, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/5 "2024-06-13T17:46:33Z")

</div>

Where's the expression/what's the output data type?  
I think there's some (misguided, legacy, has to be kept for backwards compatibility) coercion code for certain strings like on/off, yes/no to boolean values in the expression language. You need to share more about where you're authoring this expression to know where the problem lies.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 13, 2024, 9:34pm UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/6 "2024-06-13T21:34:40Z")

</div>

Would it fix it to specify Unicode to force string type?  
`if({[default]myBool}, u'ON', u'OFF')`

[Edit: The answer is no. You'll get `Error_Configuration("RuntimeException: Syntax Error on Token: 'String CONST' (Line ..., Char ...)`)  
]

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 14, 2024, 5:30am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/7 "2024-06-14T05:30:39Z")

</div>

Can you do that in expressions ?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2024, 8:44am UTC](https://forum.inductiveautomation.com/t/expression-not-returning-expected-valuebut-only-for-on-and-off-keyword/91794/8 "2024-06-14T08:44:55Z")

</div>

Apparently not - now that I've tried it.
