# Perspective Components' Value Binding

**URL:** <https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 28, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563 "2023-12-28T01:37:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Rozenshteyn](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Roman\_Rozenshteyn](https://forum.inductiveautomation.com/u/Roman_Rozenshteyn)\
**Post date:** [December 28, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/1 "2023-12-28T01:37:48Z")

</div>

Hi all,

I'm using one of the standard Perspective components for my motor faceplate and would like to bind a tag to show as the text of the value property, which works as expected.

Now I would like to add a unit to said text - something like: 10 m/s, where the 10 is my tag value.

I tried the following in a script transform:

def transform(self, value, quality, timestamp):  
value = toString(value) + 'ft/s'  
return value

I tried with and without the toString function and also different variations of it. Nothing worked.

Why doesn't this work and what can I do about it?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Ryan\_Allen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_allen/32/47013_2.png) [@Ryan\_Allen](https://forum.inductiveautomation.com/u/Ryan_Allen)\
**Post date:** [December 28, 2023, 1:53am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/2 "2023-12-28T01:53:27Z")

</div>

Try just str() instead of tostring()

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 28, 2023, 2:02am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/3 "2023-12-28T02:02:34Z")

</div>

Not sure why you would use a script transform for this, from memory they are slower to run, so they will hog more resources in bulk.

I would just do it with an expression:

`{value} + ' m/s'`

Supposed to run faster, and it's simpler to read.

---

<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:** [December 28, 2023, 2:11am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/4 "2023-12-28T02:11:20Z")

</div>

An expression binding would be as simple as,  
`{[default]MyTag} + " m/s"`  
And if you've specified the EngUnit when creating the tags (which I'm sure you have) then you can use,  
`{[default]MyTag} + " " + {[default]MyTag.EngUnit}`

Note that @David_Stone and I are inserting a space between the numerical value and the units as they're separate "words" and it improves readability. It's a recommendation on the SI standard but I don't know if there's an equivalent for the system still used in some of the colonies.

General comment: I would always try and use a separate label for the units for a few reasons:

- It allows the numbers to be right-aligned and the units left-aligned so that columns of values containing different units remain tabular even if the lengths of the units varies.
- You can use a different font weight / size / shade for the units to tone them down and reduce visual clutter. The operator will get to know the units but the numerical value is what's important to them.
- Keeping them separate means the value can be referenced by another component or expression without another call to the tag. When you mix in a string this gets messy.

---

<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:** [December 28, 2023, 2:20am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/5 "2023-12-28T02:20:30Z")

</div>

@Roman - see [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:** ![Roman\_Rozenshteyn](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Roman\_Rozenshteyn](https://forum.inductiveautomation.com/u/Roman_Rozenshteyn)\
**Post date:** [December 28, 2023, 11:25pm UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/7 "2023-12-28T23:25:33Z")

</div>

Great advice but, I'm not sure how this would be implemented with parameter passing.

I tried the most intuitive way, by go through an expression transform, which obviously didn't work out for me:

`{value} + {value.EngUnit}`

Is there a solution to this issue?

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 28, 2023, 11:27pm UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/8 "2023-12-28T23:27:27Z")

</div>

When passing a tag value, pass the tag path instead, and reference everything with that instead of a passed value.

---

<div class="post-metadata">

**Author:** ![Roman\_Rozenshteyn](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Roman\_Rozenshteyn](https://forum.inductiveautomation.com/u/Roman_Rozenshteyn)\
**Post date:** [December 28, 2023, 11:41pm UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/9 "2023-12-28T23:41:11Z")

</div>

I think we're on the same page but maybe I'm not explaining myself well. Let me try this again.

How do I replace the literal in the expression field with a pointer to the EngUnit:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/4/d4f59a14f1b661feece4da3f5f272d182a7e98a7.png)

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 28, 2023, 11:50pm UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/10 "2023-12-28T23:50:54Z")

</div>

Because you aren't passing the actual path to the tag as the parameter, use a property binding to `view.params.tagPath`, then do an expression transform:

`{value} + '/FeedbackStates/stsVelocityFb'`

Under that, do another expression transform:

`tag({value}) + ' ' + tag({value} + '.EngUnit') `

Basically you form the path to the tag, then you reference it, and the EngUnit as well.  
If you were just passing a complete tag path, you would just need the second transform.

---

<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:** [December 29, 2023, 12:03am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/11 "2023-12-29T00:03:59Z")

</div>

Create a `tagPath` parameter on the view.  
Create a **property binding** on the label like this:

![Tag value and units](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/f/8f7dac71b3b44679df9b63306987f88f2756e5cc.png)

You can get fancier and use the tag's FormatString too:

```auto
numberFormat(
	tag({value}),
	tag({value} + ".FormatString")
) 
+ " " 
+ tag({value} + ".EngUnit")

```

In my example this would result in `14.42 m/s/s`.

---

<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 29, 2023, 1:42am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/12 "2023-12-29T01:42:29Z")

</div>

Oy!

Really @Transistor, @David_Stone ?

The engineering unit retrieval belongs in a separate custom property, which then can be referenced in the original indirect tag binding's transform. (And format string, too, if wanted.)

If you find yourself using the `tag()` expression function outside an actual expression tag, you are screwing up.

---

<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:** [December 29, 2023, 3:04am UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/13 "2023-12-29T03:04:16Z")

</div>

Thanks, Phil.  
How would that work?

---

<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 29, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/perspective-components-value-binding/83563/14 "2023-12-29T13:38:20Z")

</div>

The Engineering Unit binding, on a component custom property, looks like this:

 ![20231229_0835](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aac5ff1c34b6fc81f80388ba0622c92400a04a17.png)

The Format String binding is similar, also on a component custom property.

Then the text property binding (I used a label component) would look like this:

 ![20231229_0834](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8dbd7a698c19cbe069c7571354b04c30c0c6442b.png)

No `tag()` function!

Everywhere in a UI you **think** you need a `tag()` function, train yourself to split off a custom property with an indirect binding.
