# Perspective button - write to indirect tag

**URL:** <https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749>\
**Category:** Ignition Early Access\
**Created:** [February 21, 2019, 4:50am UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749 "2019-02-21T04:50:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [February 21, 2019, 4:50am UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/1 "2019-02-21T04:50:14Z")

</div>

I have a button which, when clicked, should write a 1 to the “Start” tag in a particular UDT. instance. The desired instance is defined by a view parameter: tagPath. As far as I can tell, at this stage we have to manually write scripts to write to tags, and I figure it should be possible to construct a tag path by accessing the view parameter, and appending ‘/Start’ to the end.

I can’t work out how to get view parameters from the script though - the documentation on perspective scripting is still a little thin, and doesn’t cover that possibility.

I’m imagining something along the lines of `system.tag.write(self.view.getParam('tagPath') + '/Start', 1)`, but nothing I’ve tried along those lines has worked. How might I go about this?

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [February 21, 2019, 9:17am UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/2 "2019-02-21T09:17:33Z")

</div>

Somehow I didn't manage to find it in my searches earlier today, but I've just found this thread asking almost the same question, which has the solution.

> [@Referencing view parameters in perspective via scripting](http://forum.inductiveautomation.com/t/referencing-view-parameters-in-perspective-via-scripting/21115/2):
>
> While you are able to use system.tag.write() in perspective, you should use system.tag.writeAsync() as system.tag.write() is essentially deprecated (in your script type out “system.tag.” then hold Ctrl and tap Space to see available methods). Assuming self.parent.parent indeed refers to the View, then you should try one of two ways (which should both do the same thing): str(self.parent.parent.params.MotorNumber) or str(self.view.params.MotorNumber) Option 2 will remove the potential issue…

`system.tag.writeAsync([self.view.params.tagPath + '/Start'], [1])` should do the trick, I think. I'll try it in the morning.

Still interested to hear if anyone has a simpler way of doing indirect tag addressing on a button 🙂

(edited to add square brackets, as required for `system.tag.writeAsync()` function

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [February 21, 2019, 5:02pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/3 "2019-02-21T17:02:00Z")

</div>

It looks like the indirect binding feature seem incomplete.  
Before writing to a tag indirectly I wanted to get a indirect binding working.

Here's the setup I used:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a156ccf3ff5f84a5c06ac9198ea48460fda99672.png)

view.customer.tagPath:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/46064277c181d2167c26671d8dd404825232f54e.png)

Here's the log in the gateway console when applying this binding:

> | ExecutionQueue | 21Feb2019 11:55:39 | Uncaught Throwable during execution. |
> | --- | --- | --- |
> | java.lang.IllegalArgumentException: Malformed path: 1 | | |
> | at com.inductiveautomation.ignition.common.JsonPath.parse(JsonPath.java:199) | | |
> | at com.inductiveautomation.ignition.common.JsonUtilities.read(JsonUtilities.java:181) | | |
> | at com.inductiveautomation.ignition.common.JsonUtilities.readString(JsonUtilities.java:59) | | |
> | at com.inductiveautomation.perspective.gateway.binding.tag.TagBindingConfig.referencesFromJson(TagBindingConfig.java:48) | | |
> | at com.inductiveautomation.perspective.gateway.binding.tag.TagBindingConfig.fromJson(TagBindingConfig.java:71) | | |
> | at com.inductiveautomation.perspective.gateway.binding.tag.TagBindingFactory.create(TagBindingFactory.java:40) | | |
> | at com.inductiveautomation.perspective.gateway.binding.tag.TagBindingFactory.create(TagBindingFactory.java:20) | | |
> | at com.inductiveautomation.perspective.gateway.binding.BindingRegistryImpl.createBinding(BindingRegistryImpl.java:94) | | |
> | at com.inductiveautomation.perspective.gateway.model.AbstractBindingHarness.(AbstractBindingHarness.java:63) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$BindingPreviewSupport$PreviewBinding.(DesignerPageModel.java:160) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$BindingPreviewSupport.start(DesignerPageModel.java:118) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$BindingPreviewSupport.lambda$null$0(DesignerPageModel.java:113) | | |
> | at java.base/java.util.Optional.ifPresent(Unknown Source) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$BindingPreviewSupport.lambda$start$1(DesignerPageModel.java:113) | | |
> | at java.base/java.util.Optional.ifPresent(Unknown Source) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$BindingPreviewSupport.start(DesignerPageModel.java:112) | | |
> | at com.inductiveautomation.perspective.gateway.model.DesignerPageModel$DesignerHandlers.lambda$null$4(DesignerPageModel.java:266) | | |
> | at com.inductiveautomation.ignition.common.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:123) | | |
> | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) | | |
> | at java.base/java.util.concurrent.FutureTask.run(Unknown Source) | | |
> | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) | | |
> | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) | | |
> | at java.base/java.lang.Thread.run(Unknown Source) | | |

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 21, 2019, 5:06pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/4 "2019-02-21T17:06:09Z")

</div>

@code_skin: I believe the reference variable (“1” in your case) must be a String, but I’ll have to investigate further. For now, try renaming the reference variable to something like “path”, and see if that allows you to proceed.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 21, 2019, 5:10pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/5 "2019-02-21T17:10:18Z")

</div>

Confirmed the cause, and the good news is that a fix is already complete - it’s just awaiting internal review. The fix for this should be in place in the next few days and at that point a number will work correctly.

In the meantime, please use a String reference variable.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [February 21, 2019, 6:03pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/6 "2019-02-21T18:03:00Z")

</div>

That worked. Thanks!

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [February 21, 2019, 6:14pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/7 "2019-02-21T18:14:20Z")

</div>

Here’s what I’ve come up with; not sure if this is simpler or not for you.

I created a custom property on a button “toggleValue”  
used this indirect tag binding:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/05ef6203b6abe5e52d321afada788d91d5f4b41e.png)

Then I created a script to toggle that customProperty:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a6abdea8e8785e2ed8b946c3fcd55236c1a60f1a.png)

Alternatively, you could use the one-shot button or trigger and attached a bidirectional indirect tag binding.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 21, 2019, 6:40pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/8 "2019-02-21T18:40:30Z")

</div>

If want to go the custom property route, your script to toggle it should just be `self.custom.toggleValue = not self.custom.toggleValue` for simplicity’s sake.

Alternatively, you could have done all of this with a ToggleSwitch, which removes any of the overhead of state tracking (assuming you’re only doing boolean values).

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [February 22, 2019, 12:02am UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/9 "2019-02-22T00:02:16Z")

</div>

I tried `system.tag.writeAsync` but it did not work, with an error about not being able to coerce my tag path into a list. I thought writeAsync was for a single tag and writeBlocking was for multiple tags, but looking at the manual pages, it looks like they’re both for multiple tags and Async is just for asynchronous writing. `system.tag.write` still works, but if it’s being deprecated, is there a single-tag-write equivalent that I should be using?

---

<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:** [February 22, 2019, 12:40am UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/10 "2019-02-22T00:40:16Z")

</div>

There is no new, dedicated single-tag-write function in 8.0 - but there’s no reason not to put your single tag path in square brackets in order to send it as a list.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [November 22, 2019, 4:14pm UTC](https://forum.inductiveautomation.com/t/perspective-button-write-to-indirect-tag/22749/11 "2019-11-22T16:14:58Z")

</div>

PG, will you please provide a code snippet of `system.tag.writeAsync` usage including the callback as well. Thanks.
