# Endless error in designer

**URL:** <https://forum.inductiveautomation.com/t/endless-error-in-designer/41664>\
**Category:** Ignition\
**Tags:** ignition79, vision, scripting\
**Created:** [December 18, 2020, 11:14pm UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664 "2020-12-18T23:14:56Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 18, 2020, 11:14pm UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/1 "2020-12-18T23:14:56Z")

</div>

What is a way to run a script from a label in Vision without using runScript()?

I just had to quit developer (with about 45 mins of work in it) because I tried something similar [[runScript in expression tag](http://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378)](Runscript in expression tag) - that’s where I got the idea. Result was an error that kept running and I found no way to stop it. I tried disabling label. I tried deleting script. Error dialog kept incrementing regardless of what I tried.

1. Dialog that kept counting error rapidly (note bottom (Error 1 out of 951), gaining about 100 per second; found no way to stop this:  
 ![designer_endless_error1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/4/1429d150ba84581ea9e716d1f7fd3c3c1f96e3d6.gif)
2. Details tab of dialog:  
 ![designer_endless_error2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/daf95bf224eb0c2f2b9e5666f743cf496ef8eafe.gif)
3. Tried binding this expression to Text field - I don’t know what the 12 is for but it demanded something :-/  
 ![designer_endless_error3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/8/783ac28d597eac2cb3a2316a1c326e59b11d2cb5.gif)
4. Labels to which I tried binding:  
 ![designer_endless_error4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d8fa620da4c8966c4cd8b2c4e8bc197f4b4d1dc1.gif)
5. Trying to backtrack, I deleted script from project scope & moved it to shared, to no effect.  
 ![designer_endless_error5](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/20d00102996aaf1f275171e55ebb75f4484ee463.gif)

I didn’t know if saving project would cause this to come back to bite me when I reopened, so I decided to quit knowing will lose a lot of work. Oh well.

Below is what I’m trying to accomplish.

* * *

What I want to do is run the following script for each label (#3 above).

```auto
# Running inside Script Console, if (1 == 1): fixes indenting so function runs
#def DifferenceLastSixHours (userTag):
userTag = "VP2/Chamber_Pressure"
if (1 == 1):
	endTime = system.date.now()
	startTime = system.date.addMinutes(endTime, -360)
	returnSize = 6
	args = {
		'paths':[userTag],
		'returnFormat':'Wide',
		'startDate':startTime,
		'aggregationMode':'LastValue',
		'endDate':endTime,
		'returnSize':returnSize
	}
	dataSet = system.tag.queryTagHistory(**args)
	out = "n/a"
	for row in range(dataSet.getRowCount()):
	    for col in range(dataSet.getColumnCount()):
    		if (row > 0 and col == 1):
	    		diff = dataSet.getValueAt(row-1, col) - dataSet.getValueAt(row, col)
    			out = "%s, %.02f" % (out,diff)
	print out
#DifferenceLastSixHours("VP2/Chamber_Pressure") - doesn't work; don't know how to keep it a function in Script Console & test it, in situ.

```

This print “n/a, 0.46, 0.38, 0.41, 0.30, 0.11” in Script Console, which is all I want on the darned label!

But how to do this???

---

<div class="post-metadata">

**Author:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [December 18, 2020, 11:25pm UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/2 "2020-12-18T23:25:39Z")

</div>

It looks like your call has an error, and it’s being executed every 12 ms.

One thing you could try is passing the parameter to the `runScript` Expression Function as documented [here](https://docs.inductiveautomation.com/display/DOC79/runScript)

**runScript(scriptFunction[, pollRate][, args…])**

Option 1:

```auto
runScript("project.DifferenceLastSixHours('" + "VP2/Thermocoulpe_2" + "')", pollRate)

```

Option 2:

```auto
runScript("project.DifferenceLastSixHours", pollRate, "VP2/Thermocoulpe_2")

```

---

<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:** [December 18, 2020, 11:28pm UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/3 "2020-12-18T23:28:41Z")

</div>

Don’t use queryTagHistory() in a runScript() expression. That requires a gateway round trip and will freeze your UI for that round-trip. Use a tag history binding and run the rest of your code in a propertyChange event (on the dataset property receiving the history).

---

<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:** [December 19, 2020, 12:01am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/5 "2020-12-19T00:01:23Z")

</div>

Add a custom property to your label. Make it of type Dataset. Place your tag history binding on that custom property. Add a propertyChange event script to your label. Within that script, check for the event.propertyName == “yourCustomPropertyName”, and in that `if` section, do the rest of your processing. At the end, assign to `event.source.text`.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 12:16am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/6 "2020-12-19T00:16:41Z")

</div>

Thank you - I’m too new to this for your first answer, but I think I understand the second one, except the “place your tag history binding on that custom property”.

I’m calling historian to get a range of values and then doing some computations on them - the results script outputs don’t exist in the historian, per se.

---

<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:** [December 19, 2020, 12:19am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/7 "2020-12-19T00:19:46Z")

</div>

The tag history binding will place into the custom property the same dataset you’d get from a scripted call to query tag history, but will do it in the background without freezing the UI. When that dataset is delivered, the property will report that it changed, upon which your script can access that fresh dataset to do the rest of the calculations.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 12:22am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/8 "2020-12-19T00:22:32Z")

</div>

12 ms, that explains a lot. I will be more careful to look up all functions since I may loose all my changes in designer again. I was pasting random stuff out of forums trying to get it to work and didn’t think much of it. Thank you.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 12:35am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/9 "2020-12-19T00:35:53Z")

</div>

Ok, I did what you said and it works, but I have no idea why. Is the last line of script that’s doing all the magic?

```auto
if (event.propertyName == "text"):
     [do work]
event.source.text = out

```

I added custom property of type DataSet  
 ![custom_property](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77ad47a6e02cb5852f3563627619352bdc5c4962.gif)

Ok, now that works too - I didn’t have it in quotes, before.

```auto
if (event.propertyName == "dataSet42"):
     [do work]
event.source.text = out

```

I’m going to have to document this really well as it’s counter-intuitive on all levels 🙃

Thank you.

---

<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:** [December 19, 2020, 12:37am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/10 "2020-12-19T00:37:42Z")

</div>

No, you don’t want to watch for a change on the `text` property, you want to watch for the change on the custom property you added. You are going to write to the .text property at the end of the script–no need to watch for that.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 1:10am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/11 "2020-12-19T01:10:57Z")

</div>

One last question. I replicated the label to all the other channels and adjusted the custom property to have an unique name and modified all scripts to watch that property, but all labels are returning same output.

![all_the_same](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/1/113699ae56cf5901d583fea3e71b21442ee99a05.gif)

 ![different_dataset](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1a8a51a05f867a4d1c5e334d0d0f68c0a8a2ade7.gif)

 ![different_script](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a34712c850c38aa2315ea69f05e952db27d61db2.gif)

---

<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:** [December 19, 2020, 1:16am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/12 "2020-12-19T01:16:45Z")

</div>

Be sure to indent that final assignment to .text so it only runs on the correct event.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 1:23am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/13 "2020-12-19T01:23:15Z")

</div>

I think I’m doing this, no?

```auto
if (event.propertyName == "dataSet1"):
	endTime = system.date.now()
	userTag = "VP2/Thermocouple_2"
	startTime = system.date.addMinutes(endTime, -360)
	returnSize = 6
	args = {
		'paths':[userTag],
		'returnFormat':'Wide',
		'startDate':startTime,
		'aggregationMode':'LastValue',
		'endDate':endTime,
		'returnSize':returnSize
	}
	dataSet = system.tag.queryTagHistory(**args)
	out = "n/a"
	for row in range(dataSet.getRowCount()):
	    for col in range(dataSet.getColumnCount()):
    		if (row > 0 and col == 1):
	    		diff = dataSet.getValueAt(row-1, col) - dataSet.getValueAt(row, col)
    			out = "%s, %.02f" % (out,diff)
	event.source.text = out

```

---

<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:** [December 19, 2020, 1:24am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/14 "2020-12-19T01:24:10Z")

</div>

> [@filipg](#):
>
> I’m doing this, no?

In this full clip, yes. In the example above, no.

You also still have a call to system.tag.queryTagHistory. That shouldn't be there. Use event.newValue or event.source.dataSet1.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 1:42am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/15 "2020-12-19T01:42:58Z")

</div>

Hmm. I don’t know where to find those. I must have skipped the this step you recommended “Place your tag history binding on that custom property” - how do I do that?

For now, I got it to work by changing labels’ scripts back to:  
if (event.propertyName == “text”):

![kinda_working](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/afe6f82b7e2d76e342f60388644083c0d1bc1e95.gif)

(for debugging changed out = “n/a” to out = “%s n/a” % userTag)

---

<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:** [December 19, 2020, 1:46am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/16 "2020-12-19T01:46:18Z")

</div>

I think you need to spend some time with Inductive University:

[https://www.inductiveuniversity.com/videos/tag-historian-binding/7.9](https://www.inductiveuniversity.com/videos/tag-historian-binding/7.9)

[https://www.inductiveuniversity.com/courses/scripting/7.9#component-scripting](https://www.inductiveuniversity.com/courses/scripting/7.9#component-scripting)

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [December 19, 2020, 2:35am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/17 "2020-12-19T02:35:41Z")

</div>

I appreciate the links. I viewed those before but they didn’t make sense to my predicament. This time… I still don’t see where that gets me - how can I avoid system.tag.queryTagHistory()?

Script uses special parameters to system.tag.queryTagHistory() to **pull out only single values on the hour going back 6 hours**. Then, it subtracts these from “previous” hour’s values to get “difference” (12AM,2.2,1AM,2.0,2AM,1.8) so difference would be 0.2 and 0.2 (to gain insight to rate of change, which is non-linear).

I don’t know how to make that happen WITHOUT using system.tag.queryTagHistory(). Or do you mean that I need to query the slice with system.tag.queryTagHistory(event.return.dataSet1)?

Also, for the slices of history I need (6 hours), I will be copying 2500 rows (of float) for each label ( times 14) - or is Ignition smarter than that? And I have to associate each historical tag with its slice (dataset), instead of just changing a variable in the script. Is that less of a hit than original script?

For now, I will restrict that dialog to just engineer role so operators can’t run it, which will limit it to my instance 🙂

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [December 19, 2020, 4:17am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/18 "2020-12-19T04:17:18Z")

</div>

Honestly, I think that what you’re doing will be better suited as a gateway-level task. I generally try to avoid putting logic like this in the client since then those same requests cause duplicative effort at the gateway as you launch additional clients. Instead, consider using a gateway script to periodically compute and write these results to tags, and then simply bind to those tags in the client. It will perform and scale better, and keep the visualization side much simpler (and faster there too).

---

<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:** [December 19, 2020, 11:16am UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/19 "2020-12-19T11:16:25Z")

</div>

> [@filipg](#):
>
> how can I avoid system.tag.queryTagHistory()?

You are calling it once. A history binding can do the same. Place those args on the tag history binding. It will (in the background) call the equivalent query and deliver the dataset to the bound property. The custom property's value will be that dataset. Just run your differencing loops using that property value as the input dataset.

---

<div class="post-metadata">

**Author:** ![filipg](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@filipg](https://forum.inductiveautomation.com/u/filipg)\
**Post date:** [January 6, 2021, 7:24pm UTC](https://forum.inductiveautomation.com/t/endless-error-in-designer/41664/20 "2021-01-06T19:24:48Z")

</div>

Kevin, so I missed “[t]hat requires a gateway round trip and will freeze your UI for that round-trip” being the source of the penalty in Phil’s original response - thanks for pointing out that moving to gateway is an option to avoid this.

In fact, what brought me back to this forum is that I am now addicted to this (new to me) functionality\* and moving these functions to gateway will let me compute data (safely) for others and for triggering higher-level (process-envelope excursion type) alarms.

I am learning about data structures, but will most likely flesh out the screens I need and ask our local integrator to quote implementation - they have been great about teaching me how to reuse & extend new code.

Thank you.

\*I inherited several largish systems that are key to our plant, but that were not well understood by their OEMs (very primitive UI, no alarms above OL/OT, useless manuals, etc). I’m looking to make improvements and can’t lean on OEM (staff retired/left); only have data gathered by Ignition, which I get to write, with your invaluable help 🙂
