# Access UDT parameter in script

**URL:** <https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824>\
**Category:** Ignition\
**Created:** [August 28, 2019, 7:55am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824 "2019-08-28T07:55:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [August 28, 2019, 7:55am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/1 "2019-08-28T07:55:45Z")

</div>

Hi  
How can I access UDT parameter in tag change event script?

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [August 28, 2019, 11:42am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/2 "2019-08-28T11:42:25Z")

</div>

I have used system.tag.read(’[.]…\Parameters.ABC’), where ABC is the parameter name, successfully.

Obviously the relative path changes based on your folder structure in the UDT.

Interested to know if there is a better way, such as {ABC} in the references

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [August 29, 2019, 4:52am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/3 "2019-08-29T04:52:54Z")

</div>

Hi Deon  
I doesn’t in tag change event script in udt.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [August 29, 2019, 9:45am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/4 "2019-08-29T09:45:06Z")

</div>

I don’t know if it’s possible. But we usually have a number of memory tags inside a folder of our UDT, that are just bound to those parameters.

Then those memory tags can be retrieved just like regular tags in the script.

---

<div class="post-metadata">

**Author:** ![Paullys50](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paullys50/32/3324_2.png) [@Paullys50](https://forum.inductiveautomation.com/u/Paullys50)\
**Post date:** [August 29, 2019, 12:18pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/5 "2019-08-29T12:18:33Z")

</div>

Depends on the version. v8.0 makes parameters easier to access than v7.9.

v7.9 I’ve found it easier to do as Sanderd17 suggested.

v8.0 do as deon.korb suggests.

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 29, 2019, 2:53pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/6 "2019-08-29T14:53:46Z")

</div>

@Paullys50 and @deon.korb

I have a similar question for the struct member reading of UDT in script with Ignition V8.0

The [default]VetctorTag/Vector is a OPC UDT tag, which can be read by system.tag.read function as shown in below snapshot that triggered by a button click operation.

This OPC tag has three members X, Y and Z. In fact, I want to just parse and print its member X.

It seems that system.tag.read(’[default]VetctorTag/Vector.X’) doesn’t work. Could you help to give suggestion of it?

Thanks in advance

 ![png1](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e97a66181fd633c224c6db50c5f749a2822c118b.png)

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [August 29, 2019, 3:07pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/7 "2019-08-29T15:07:20Z")

</div>

> [@dawei.liu](#):
>
> system.tag.read(’[default]VetctorTag/Vector.X’)

system.tag.read(’[default]VetctorTag/Vector/X’) should work.

I usually use the browsers, such as a Perspective binding, to figure out the syntax first.

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 30, 2019, 3:35am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/8 "2019-08-30T03:35:56Z")

</div>

@deon.korb

Thanks for your info, the way works for the memory tags, but doesn’t work for OPC UDT tags.

The “[default]VetctorTag/Vector” is a OPC UDT tag that I dragged from a third part OPC UA server. Its whole data of X, Y, Z can be get by the with system.tag.read(’[default]VetctorTag/Vector/X’) ,  
but using system.tag.read(’[default]VetctorTag/Vector/X’) doesn’t work for reading its struct member X.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [August 30, 2019, 4:27am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/9 "2019-08-30T04:27:14Z")

</div>

What about [this post](http://forum.inductiveautomation.com/t/opc-ua-struct-data-type/26905/3)?

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 30, 2019, 4:31am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/10 "2019-08-30T04:31:54Z")

</div>

@zxcslo  
Thanks for your info, I knew we could use JsonGet to retrieve Json format UDT of OPC tag.

Just want to know if it is possible to use system.read() to achieve this goal in script, because the jsonGet() function is only used in expression and it can’t be used in script.

If it provide the jsonGet() function in script, then it solve my issues.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [August 30, 2019, 5:43am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/11 "2019-08-30T05:43:54Z")

</div>

What about this:

 ![tagReadJson](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/659fac34e3c23b986c58c4059cc0c82dcde6dbd5.png)

or this:

```auto
value = system.tag.read("New Tag3").value
value = system.util.jsonDecode(value)
print value
print value['X']
print value['Y']
print value['Z']

```

[This post](http://forum.inductiveautomation.com/t/jsonset-workaround-in-script/27560/2) explain it…  
EDIT: I just realized that @Kevin.Herron already explained this to you 11 days ago…?

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 30, 2019, 12:54pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/12 "2019-08-30T12:54:22Z")

</div>

@zxcslo  
Thanks for your comments.  
I’ve try with your suggestion, it only works without the calling the eval() function as shown in the green box of below snapshot.  
If we use eval() function or system.util.jsonDecode() function, both of them can’t parse the “Document” datatype, which is in fact printed as  
\<type ‘com.inductiveautomation.ignition.common.script.adapters.PyDocumentObjectAdaper’\> as shown in below snapshot.

 ![png1](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d0a79c3ffd36e1ec65f23d632c15ce8ffee0d439.png)

It seems that the Document type can’t be parsed by jsonDecode() function.  
BTW, in fact, I’ve asked the question for document type UDT parsing as you mentioned, the jsonDecode() function also doesn’t work for that case, I use another workaround by using tags directly in script to solve my problem in that thread.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [August 30, 2019, 3:07pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/13 "2019-08-30T15:07:00Z")

</div>

Well... then I'm 'lost'...  
In my case, when I drag from OPC browser the UDT (struct) tag from my S7-1500 OPC UA server, that tag is Unicode string type (JSON). You obviously get Document type.

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/3d7363b150f0f14cf40c506cababdc9a5a8dc1bb.png)  
I'm using v7.9.12. You're using v8.  
In v8 system.tag.read is deprecated (but it'll still work, for backward compatibility). The new function is [system.tag.readAsync](https://docs.inductiveautomation.com/display/DOC80/system.tag.readAsync).  
Maybe system.tag.read was changed in v8...??? Maybe @Kevin.Herron can explain?

EDIT: I read the other post it again and it seems that, because tag system is completely changed in v8:

> [@jsonSet workaround in script](https://forum.inductiveautomation.com/t/jsonset-workaround-in-script/27560/2):
>
> edit: the Document object in our tag system might be a mutable GSON object and not a String… I’ll have to look at this in a bit when I get the office.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 30, 2019, 3:51pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/14 "2019-08-30T15:51:45Z")

</div>

`system.tag.read` is fine but its most direct replacement in 8.0 is `system.tag.readBlocking`.

@dawei.liu if you’re getting a document type just call `str()` on it first.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [August 30, 2019, 4:36pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/15 "2019-08-30T16:36:00Z")

</div>

> [@Kevin.Herron](#):
>
> but its most direct replacement in 8.0 is `system.tag.readBlocking`

Yes, my bad... 😳  
Anyway, good call on str()... 👍

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 31, 2019, 3:23am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/16 "2019-08-31T03:23:45Z")

</div>

@Kevin.Herron and @zxcslo

Really appreciate your help, the str() works well and solve my issues

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [August 31, 2019, 2:11pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/17 "2019-08-31T14:11:26Z")

</div>

I understood the question incorrectly, but it is very interesting to see how to read a struct up and then access it’s members.

How would you write back to one member of the struct then?

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [September 2, 2019, 3:33am UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/18 "2019-09-02T03:33:41Z")

</div>

Just as Kevin’s suggestion in [jsonSet workaround in script](http://forum.inductiveautomation.com/t/jsonset-workaround-in-script/27560/2)

I just tested that it’s possible to write back the struct value through script (Ignition version 8.0.4 Nightly)

With below script, the UDT member ‘param1’ of ‘OPC\_tag’ can be updated and writen back to OPCUA server.

value1 = system.tag.read(‘OPC\_tag’).value  
value1 = system.util.jsonDecode(str(value1))  
value1[‘param1’] = ‘updated\_param1\_value’  
value2 = system.util.jsonEncode(value1)  
system.tag.write(‘OPC\_tag’, value2)

---

<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:** [September 2, 2019, 5:53pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/19 "2019-09-02T17:53:32Z")

</div>

Doesn’t that write the whole structure back? Less than optimal.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 2, 2019, 5:57pm UTC](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824/20 "2019-09-02T17:57:50Z")

</div>

It does, and it’s required because his tag represents the whole structure. Reading the whole structure is the only way to get decent performance out of built-in OPC UA servers like the one on the S7-1500.

It would be ideal if the client could magically derive the NodeId for any given structure member and write to just that Node in the server, but it’s not even a given that a server exposes the members as individual Nodes.

[Next page](https://forum.inductiveautomation.com/t/access-udt-parameter-in-script/27824.md?page=2)
