# UDT template button write to tag script

**URL:** <https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 5, 2023, 9:11am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510 "2023-11-05T09:11:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryon\_F](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@Bryon\_F](https://forum.inductiveautomation.com/u/Bryon_F)\
**Post date:** [November 5, 2023, 9:11am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/1 "2023-11-05T09:11:49Z")

</div>

I'm quite new to Ignition. I apologize in advance for not finding the forum or manual blurb that is the answer to my problem.

Situation:  
I have many motors so making a template. I'm mimicking "UDTs and Template Views" from IA University.

Problem:  
My onActionPerformed Script for my Primary Button is not turning on my UDT instance tag.

I've read quite a bit in the Perspective 8.1 manual and read and tried a lot from the forum but haven't found the solution. (BTW-a huge thank you to all contributors to the forum!)

I'm on my 400th variation of the script and so far, no joy. I don't get errors anymore and thought, "that's good". But in this case, no news isn't good news.

Primary Button onActionPerformed script:

```auto
def runAction(self, event):
	startPath = {self.view.params.SimpleMtr.Start_SCADA}
	system.tag.writeBlocking("startPath","true")

```

If I change the script to a discrete path, it works but of course, only for that one tag.

```auto
startPath = "[default]testSimpleMtr_2/Start_SCADA"
system.tag.writeBlocking(startPath,"true")

```

UDT instance:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a4b40c6bcae021b43b66dce81c36c6cb9443414c.png)

Params:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f672735d53fdd012c1e5989fffb9db9852f49daa.png)

Eventually, I'll go the "dropConfig" route but I have to get this working first.

Gentlemen, I greatly appreciate the feedback!

Bryon

---

<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:** [November 5, 2023, 9:27am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/2 "2023-11-05T09:27:52Z")

</div>

A couple of pointers to get you going:

> `{self.view.params.SimpleMtr.Start_SCADA}`

You are creating a **dictionary**. `system.tag.writeBlocking` requires a **list**.

> `system.tag.writeBlocking("startPath", "true")`

Two problems here. You are passing literal strings into the function instead of variables. `"startPath"` is not the same as `startPath`. Similarly `"true"` is not the same as `True`.

Try this:

```auto
def runAction(self, event):
	startPath = [self.view.params.SimpleMtr.Start_SCADA]
	values = [True]
	system.tag.writeBlocking(startPath, values)

```

> **Gentlemen** , I greatly appreciate the feedback!

\<Cough!\>

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [November 5, 2023, 11:47pm UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/3 "2023-11-05T23:47:23Z")

</div>

It also appears that `self.view.params.SimpleMtr.Start_SCADA` is the _value_ of the Start SCADA tag, not the path.

I would restructure this view so that the only param is a tag path to a simple motor UDT. Then add a custom prop called SimpleMtr which has an indirect tag binding to that tag path param.

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [November 5, 2023, 11:48pm UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/4 "2023-11-05T23:48:01Z")

</div>

> Gentlemen, I greatly appreciate the feedback!

Also not to be _that_ person but we're not all gentlemen here, it's good practice to use gender neutral language.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 6, 2023, 12:01am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/5 "2023-11-06T00:01:12Z")

</div>

> [@amy.sudibyo](#):
>
> it's good practice to use gender neutral language.

Maybe an apostrophe will accomodate all genders 😆  
"gentle'men"

We are, at least you and I, Austra'ans after all: land of abbreviations

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [November 6, 2023, 12:03am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/6 "2023-11-06T00:03:48Z")

</div>

I think you misspelt Strayans 😃

---

<div class="post-metadata">

**Author:** ![Bryon\_F](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@Bryon\_F](https://forum.inductiveautomation.com/u/Bryon_F)\
**Post date:** [November 6, 2023, 7:21am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/7 "2023-11-06T07:21:59Z")

</div>

Crikey's, that was fast!

> [@Transistor](#):
>
> Try this:
> 
> ```auto
> def runAction(self, event):
> startPath = [self.view.params.SimpleMtr.Start_SCADA]
> values = [True]
> system.tag.writeBlocking(startPath, values)
> 
> ```

Sorry for late response. Was busy trying suggestion and the myriad of variations, none of which worked. I got the below "string error" as a result of the above script.

```auto
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 4, in runAction
TypeError: expected a str

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 4, in runAction
TypeError: expected a str

```

I'm actually working toward a dropConfig with my SimpleMtr template. I had problems getting it to work so I backed up to where I am now. I'm finding that I am unable to get the correct onClick script syntax for the button of my template instance to work.

I think you're right about the value being passed instead of the path. This works but I can't figure out how to get it to interact via the view.params... path.

```auto
	startPath = ["[default]testSimpleMtr_2/Start_SCADA"]
	values = [True]
	system.tag.writeBlocking(startPath, values)

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 6, 2023, 7:58am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/8 "2023-11-06T07:58:52Z")

</div>

> [@Bryon\_F](#):
>
> think you're right about the value being passed instead of the path. This works but I can't figure out how to get it to interact via the view.params... path

You just need to pass in a tag path to your View's param, not a value/binding to a tag

---

<div class="post-metadata">

**Author:** ![Bryon\_F](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@Bryon\_F](https://forum.inductiveautomation.com/u/Bryon_F)\
**Post date:** [November 6, 2023, 8:39am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/9 "2023-11-06T08:39:29Z")

</div>

That would be great! I've tried but I don't know how.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 6, 2023, 9:32am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/10 "2023-11-06T09:32:03Z")

</div>

Find your UDT instance, right click, copy path  
Paste the path into the param value in the embedded View. In the view you'll then need to append onto this udt instance path the relative path to the tag within the UDT instance.

Eg  
Expression

```auto
{self.view.custom.udtInstancePath} + '/tagName' 

```

Script

```auto
'{}/tagName'.format(self.view.custom.udtInstancePath) 

```

---

<div class="post-metadata">

**Author:** ![Bryon\_F](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@Bryon\_F](https://forum.inductiveautomation.com/u/Bryon_F)\
**Post date:** [November 8, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/11 "2023-11-08T15:58:03Z")

</div>

Hey All,

Thank you so much for your input! It's so nice to have a place to learn!  
Here's the version I finally got to work:

```auto
def runAction(self, event):
	providerPath = "[default]"
	tagPath = (self.view.params.SimpleMtr.pathToParentFolder)
	buttonPath = providerPath + tagPath + "/Start_SCADA"
	system.tag.writeBlocking(buttonPath, "true")

```

Still new to JSON and Python. Simple braces didn't occur to me until I stared at the previous post.  
That said, I'd like to pass in the provider. Not all of my tags are in [default]. (Still sorting out the ramifications of where I put tags.)

Cheers, and thank you again!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 9, 2023, 6:55am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/12 "2023-11-09T06:55:59Z")

</div>

> [@Bryon\_F](#):
>
> `"true"`

This should be `True`, not a string

> [@Bryon\_F](#):
>
> `(self.view.params.SimpleMtr.pathToParentFolder)`

Not sure why you surround this in braces, but these aren't needed. Braces usually define a tuple (a type of immutable array), but only when there are 2 or more values, or you add a comma to the end of a single value. You don't have a comma at the end so I think it's just effectively returning the string value into the variable. In any case, it could be super confusing to someone looking at it, so I'd remove them.

Also, I'd recommend getting used to using the str.format function as it handles converting values passed to it into strings for you rather than having to explicitly do this yourself

---

<div class="post-metadata">

**Author:** ![Bryon\_F](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@Bryon\_F](https://forum.inductiveautomation.com/u/Bryon_F)\
**Post date:** [November 9, 2023, 7:18am UTC](https://forum.inductiveautomation.com/t/udt-template-button-write-to-tag-script/81510/13 "2023-11-09T07:18:50Z")

</div>

> [@nminchin](#):
>
> Not sure why you surround this in braces

Purely ignorance.

> [@nminchin](#):
>
> Braces usually define a tuple (a type of immutable array), but only when there are 2 or more values, or you add a comma to the end of a single value. You don't have a comma at the end so I think it's just effectively returning the string value into the variable. In any case, it could be super confusing to someone looking at it, so I'd remove them.

Had no idea. Thanks for the lesson!

> [@nminchin](#):
>
> I'd recommend getting used to using the str.format function

Will do.
