# String in a cell of a query to a label transform

**URL:** <https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870>\
**Category:** Ignition\
**Created:** [February 8, 2022, 5:00pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870 "2022-02-08T17:00:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 8, 2022, 5:00pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/1 "2022-02-08T17:00:51Z")

</div>

What I am trying to show  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aaf69ff999c9dfcb844fce8db4d6605bac5da6cc.png)

what I am showing right now from binding the label to my query:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fbe92a4d7ebe04235f2365b1410ec5ab73589828.png)

the example result of my query:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/3/f3b7794bd9ce3e9b8f38890fbcfd1d6744ed0d9a.png)

I am not really sure how to transform this.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e948c6194de93f6758a1a99210678668a5d74de8.png)

my query is receiving parameters to figure out which message to show

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 8, 2022, 5:11pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/2 "2022-02-08T17:11:09Z")

</div>

If you are only returning a single message from your query, you could change the query to be a scalar query so it returns a value and not a dataset.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 8, 2022, 9:04pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/3 "2022-02-08T21:04:21Z")

</div>

thanks  
I like the new profile pic/logo you have too

I also used

```auto
if value < 0:
 value=" "
  return value
else:
  return value

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 8, 2022, 9:13pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/4 "2022-02-08T21:13:27Z")

</div>

```auto
if value < 0:
    value = " "
return value

```

Is more pythonic, no need for the else. Though, based on your original post, this seems to not be the correct test. What do you think you’re testing for with `if value < 0`?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 8, 2022, 10:06pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/5 "2022-02-08T22:06:05Z")

</div>

I was trying to test for null haha, but I couldn’t get it to work, then less than zero “worked” haha

---

<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:** [February 8, 2022, 11:02pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/6 "2022-02-08T23:02:33Z")

</div>

In Python it’s  
`if myVariable is None:`.

In expression language it’s  
`if(isNull(myVariable), ..., ...)`

For your original problem:  
`[{"Description": "10 CB212 control voltage 24VDC +12 tripped "}]`  
you’ve got a dictionary `{ }` inside a list `[]`. You can retrieve the message string:

1. Switch the returned format to JSON (Document) format.
2. Add a script transform.
3. Modify the `return value` line to `return value[0]['Description']`.  
The [0] is because the dictionary is the 0th element in the list.

You’ve already got a fix using the Scaler option but this may come in handy for other tasks.  
`

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 9, 2022, 2:58pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/7 "2022-02-09T14:58:32Z")

</div>

Thanks very much for the additional information.

That makes sense.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 9, 2022, 4:00pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/8 "2022-02-09T16:00:45Z")

</div>

You could do it as a one line with:

```auto
return value if value is not None else " "

```

Though that is a little cryptic in this case, but it’s nice to know it’s a possibility.

Also be careful because, None is not equivilent to `""`

---

<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:** [February 9, 2022, 6:57pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/9 "2022-02-09T18:57:25Z")

</div>

`" "` is not equal to `""` either. Why return a space and not an empty string?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 9, 2022, 7:19pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/10 "2022-02-09T19:19:28Z")

</div>

Yeah, I know. I was more cautioning against the thought that:

`if value == ""` was the same as `if value is none`

I used `" "` in this case because that is what the OP used

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 9, 2022, 9:25pm UTC](https://forum.inductiveautomation.com/t/string-in-a-cell-of-a-query-to-a-label-transform/55870/11 "2022-02-09T21:25:19Z")

</div>

If you were asking me, I didn’t have a particular reason.

I usually use a space. I have a vague memory of some software skipping my cell when it was an empty string, but I don’t recall the specifics. Or maybe it was just the abundance of null errors I used to get programming Java, and no idea where they were haha

I am not sure.
