# Using system.tag.readBlocking and turning into string

**URL:** <https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [April 4, 2022, 1:45am UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984 "2022-04-04T01:45:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casu](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Casu](https://forum.inductiveautomation.com/u/Casu)\
**Post date:** [April 4, 2022, 1:45am UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/1 "2022-04-04T01:45:08Z")

</div>

So I’ve taken a piece of data from my tag through using system.tag.readBlocking. It comes out as [“data”], but I need to concatenate the actual word data with a string, so I used str() on the array.

It returns the entire tag value, quality and time and still outputs as an array. I’ve tried pulling the first value out however it does not work. Additionally, using the .value on the system.tag.readBlocking output does not pull only the value out either.

The system.dataset.toDataSet function does not work either unfortunately.

Is there a way to convert the actual value into a string?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 4, 2022, 2:07am UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/2 "2022-04-04T02:07:36Z")

</div>

I suggest another read of the manual. `system.tag.readBlocking` returns a list of objects. You will need to get the value attribute of whatever object in your list you are wanting to use. The manual includes examples that show you how to do this.  
[https://docs.inductiveautomation.com/display/DOC80/system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC80/system.tag.readBlocking)

---

<div class="post-metadata">

**Author:** ![Casu](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Casu](https://forum.inductiveautomation.com/u/Casu)\
**Post date:** [April 4, 2022, 7:33pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/3 "2022-04-04T19:33:35Z")

</div>

I’ve solved this through using the str() function and then a mid() function - since using str() on the system.tag.readBlocking also gave the quality and time - apologies, I wasn’t clear enough on the actual issue, which was the extra input.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 4, 2022, 7:41pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/4 "2022-04-04T19:41:05Z")

</div>

I still think you have something goofy going on. Try something like this in the script console.

```auto
tags = ["[default]Tag 1"]
results = system.tag.readBlocking(tags)
print results[0].value

```

---

<div class="post-metadata">

**Author:** ![Casu](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Casu](https://forum.inductiveautomation.com/u/Casu)\
**Post date:** [April 4, 2022, 8:03pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/5 "2022-04-04T20:03:57Z")

</div>

I tried this out - this also works thank you. I also will need to change this to a string to manipulate it too. Cheers

---

<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:** [April 4, 2022, 8:06pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/6 "2022-04-04T20:06:50Z")

</div>

> [@Casu](#):
>
> I also will need to change this to a string to manipulate it too.

Why? Is not already a string?

---

<div class="post-metadata">

**Author:** ![Casu](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Casu](https://forum.inductiveautomation.com/u/Casu)\
**Post date:** [April 4, 2022, 8:13pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/7 "2022-04-04T20:13:45Z")

</div>

For some reason, it doesn’t come out as a string - I tested and the only way I could add it to another string was to first use the str() function, even using josborn’s method.

---

<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:** [April 4, 2022, 8:15pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/8 "2022-04-04T20:15:14Z")

</div>

What is the type of the tag?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 4, 2022, 8:15pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/9 "2022-04-04T20:15:41Z")

</div>

If your tag type is string you will get a string value. Also please don't do this, that makes me cringe.

> [@Casu](#):
>
> I’ve solved this through using the str() function and then a mid() function

---

<div class="post-metadata">

**Author:** ![Casu](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Casu](https://forum.inductiveautomation.com/u/Casu)\
**Post date:** [April 4, 2022, 8:26pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/10 "2022-04-04T20:26:55Z")

</div>

Its a list type with a value, quality and timestamp

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 4, 2022, 8:28pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/11 "2022-04-04T20:28:04Z")

</div>

Check here:

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

---

<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:** [April 4, 2022, 9:08pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/12 "2022-04-04T21:08:36Z")

</div>

Let’s start from first principles.

When you use [`system.tag.readBlocking`](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking), the return value is a _list_ of [`QualifiedValue`](https://docs.inductiveautomation.com/display/DOC81/Scripting+Object+Reference#ScriptingObjectReference-QualifiedValue) objects.

To extract the _first_ element of the list, use subscript `0` to retrieve the first element: `qualifiedValue = listOfValues[0]`. Now you have a `QualifiedValue` object. To retrieve the _actual value_, which can be _any_ type, use `getValue()`, or, better, `.value`: `actualValue = qualifiedValue.value`.  
The type of `value` at this point will be whatever the tag’s type is, per @josborn’s post above.  
If your tag is _not_ a string, _and you actually need to do a string formatting operation_, you can ask it for its string representation using the Python builtin `str` function. _This is a lossy operation_ - the string representation of an object is not guaranteed to and indeed almost never does encode as much information as the actual type.

You should drive logic from the string representation of a value approximately **never**. For presentation, sure, it’s fine, although if you have a richer type you might still lose information (even a simple floating point might not be represented the way you want it to be if you simply call `str`).

---

<div class="post-metadata">

**Author:** ![eric.peery](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eric.peery/32/11897_2.png) [@eric.peery](https://forum.inductiveautomation.com/u/eric.peery)\
**Post date:** [April 8, 2022, 1:03pm UTC](https://forum.inductiveautomation.com/t/using-system-tag-readblocking-and-turning-into-string/57984/13 "2022-04-08T13:03:03Z")

</div>

Just to summarize the above and provide a 1-line answer for your script, to get your the current value out of a single tag you would use:

**myValue = system.tag.readBlocking([_myTagPath_])[0].value**

if the tag is not a string type you would change it to:

**myValue = str(system.tag.readBlocking([_myTagPath_])[0].value)**

but always remember the lossy aspect of this that Mr. Griffith mentions.
