# ExpressionType with string as return type (mappView)

**URL:** <https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282>\
**Category:** HMI & Visualization\
**Tags:** mapp-view\
**Created:** [December 20, 2024, 6:52am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282 "2024-12-20T06:52:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_Pracht](https://avatars.discourse-cdn.com/v4/letter/c/FF8800/32.png) [@Carl\_Pracht](https://community.br-automation.com/u/Carl_Pracht)\
**Post date:** [December 20, 2024, 6:52am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282/1 "2024-12-20T06:52:32Z")

</div>

I want to use an Expression resp. an ExpressionType to set the style of an svg image based on an OPC UA variable.

This is basically working if the operation is as simple as a pure string, eg. “green”. But what would the operation have to look like to do the following? The code is not working, but it should show the idea.

```auto
<?xml version="1.0" encoding="utf-8"?>
<ExpressionTypeSet id="expressiontype_1" xmlns="http://www.br-automation.com/iat2016/expressionType/v1">
  <ExpressionTypes>
	<ExpressionType name="checkGreen" datatype="ANY_STRING">
		<Operands>
			<Operand name="inState" datatype="ANY_INT" />
		</Operands>
		<Operation>
			inState > 0 ? "red" : "green"
		</Operation>
	</ExpressionType>
  </ExpressionTypes>
</ExpressionTypeSet>

```

---

<div class="post-metadata">

**Author:** ![Simon\_Stoll](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/simon_stoll/32/445_2.png) [@Simon\_Stoll](https://community.br-automation.com/u/Simon_Stoll)\
**Post date:** [December 20, 2024, 7:30am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282/2 "2024-12-20T07:30:06Z")

</div>

Hi Carl,

I don’t know how exactly to do this with expressions.

But I can suggest an alternative solution using ListBindings.

First of all you have to define two SessionVars for different colors “red” and “green”:

```auto
<Variable name="MyVarRed" xsi:type="ANY_STRING" value="red" />
<Variable name="MyVarGreen" xsi:type="ANY_STRING" value="green" />

```

You can bin these vars directly to target via list binding using your instate as selector:

```auto
<Binding mode="oneWay"> <!-- -->	
  <Source xsi:type="listElement">
    <Selector xsi:type="session" refId="inState" attribute="value" /> 
    <be:List xmlns:be="http://www.br-automation.com/iat2015/bindingListEmbedded/engineering/v2" xsi:type="be:session" attribute="value">
      <bt:Element index="0" refId="MyVarGreen" />
      <bt:Default refId="MyVarRed" /> <!-- if <> 0 -->
    </be:List>
  </Source>	
  <Target xsi:type="session" refId="YourTargetString" attribute="value" />
</Binding>

```

I think this way is (a little) easier than working with expressions. 🙂

**Note:** default switch only works for value \<\> 0 not for values \> 0

Is this a solution for you?

Sincerly Simon

---

<div class="post-metadata">

**Author:** ![Carl\_Pracht](https://avatars.discourse-cdn.com/v4/letter/c/FF8800/32.png) [@Carl\_Pracht](https://community.br-automation.com/u/Carl_Pracht)\
**Post date:** [December 20, 2024, 7:40am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282/3 "2024-12-20T07:40:17Z")

</div>

Hello Simon,

thank you for your quick response. What I didn’t mention is that the inState is bitwise interpreted and needs to be compared to a bitmask, i.e. I need to check if certain bits are set.  
Do you have idea how to accomplish that?

Sincerely  
Carl

---

<div class="post-metadata">

**Author:** ![Simon\_Stoll](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/simon_stoll/32/445_2.png) [@Simon\_Stoll](https://community.br-automation.com/u/Simon_Stoll)\
**Post date:** [December 20, 2024, 7:52am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282/4 "2024-12-20T07:52:40Z")

</div>

Hmm. In mappView (as far I know) it’s only posible to compare equal = / not equal \<\>.

Often it’s easier to do such comparisons in the PLC and bind the result (string in your case) via OPC UA to mappView.

Maybe someone else can give some input 🤔 🤔

---

<div class="post-metadata">

**Author:** ![Carl\_Pracht](https://avatars.discourse-cdn.com/v4/letter/c/FF8800/32.png) [@Carl\_Pracht](https://community.br-automation.com/u/Carl_Pracht)\
**Post date:** [December 20, 2024, 10:22am UTC](https://community.br-automation.com/t/expressiontype-with-string-as-return-type-mappview/5282/5 "2024-12-20T10:22:27Z")

</div>

Thank you again. I will implement it in the PLC.  
Have a nice weekend!
