# invokeLater in Expession binding

**URL:** <https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187>\
**Category:** Ignition\
**Created:** [June 30, 2020, 10:00am UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187 "2020-06-30T10:00:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [June 30, 2020, 10:00am UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/1 "2020-06-30T10:00:56Z")

</div>

I have a template which has approximately 20 internal properties. Each property has a expression binding. It is either reading a value from a tag or calling a script(using `runScript`) to get its value. Functions being called in `runScript` use some of the other properties as parameters.

A window which has the this template’s instance takes up to 20 second to open. After opening initially it shows tag binding error icon which disappears in couple of seconds.

Is there any way this delay can be reduced? Is `invokeLater` function is useful in this case and can it be called in expression binding? or is there any other approach to minimize the delay?

---

<div class="post-metadata">

**Author:** ![jonathan.taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonathan.taylor/32/4048_2.png) [@jonathan.taylor](https://forum.inductiveautomation.com/u/jonathan.taylor)\
**Post date:** [June 30, 2020, 11:12am UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/2 "2020-06-30T11:12:51Z")

</div>

Have you considered wrapping the expressions that cause the binding errors with the try() function? That way you can force it to default to a set value whilst it is calculating.

---

<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:** [June 30, 2020, 12:16pm UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/3 "2020-06-30T12:16:27Z")

</div>

There’s a fair amount of overhead using `runScript` (or my `objectScript`). Consider using a single runScript call supplying all necessary parameters to return a _ **dataset** _ with columns for each of the twenty calculated template parameters. Elsewhere in the template use `try({TemplateName.DatasetParam}[0,'myParam'], startupDefault)` instead of `{TemplateName.myParam}`.

---

<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:** [June 30, 2020, 12:19pm UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/4 "2020-06-30T12:19:05Z")

</div>

Also, don’t make database calls or tag reads or any other calls that require a gateway round-trip. Do all of that kind of stuff with the appropriate asynchronous bindings and feed the results to runScript as extra parameters.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 30, 2020, 1:07pm UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/5 "2020-06-30T13:07:31Z")

</div>

Just to tack on to @pturmel , as a general rule, it’s good design and more optimal to make as minimal calls to the database as possible. If you have 20 internal properties each with their own database request - now say you need to manually refresh them - thats 20 lines of code. If you could do it in one database and use the `try()` technique he mentions, now if you need to refresh the whole scree, its only a single line of code.

Alternatively, if you have it at a polling rate instead of coded refreshes, you’ve just cut your number of database requests by 95% going from 20 calls to 1.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [June 30, 2020, 1:31pm UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/6 "2020-06-30T13:31:52Z")

</div>

Thanks for your reply.  
I am not sure if I understand what asynchronous binding is. Could you please cite an example? E.g. to read a tag, what should I use to get a tag value instead of `tag(tagPath)` in expression binding?

---

<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:** [June 30, 2020, 1:43pm UTC](https://forum.inductiveautomation.com/t/invokelater-in-expession-binding/36187/7 "2020-06-30T13:43:15Z")

</div>

Use direct and indirect tag bindings on additional custom properties. If you are using the `tag()` function anywhere other than a gateway expression tag, you are screwing up. Tag bindings and query bindings do their work on background threads, leaving the user interface thread (Java Swing is single-threaded) alone until they have results to deliver. Expression bindings, including bindings involving tag() and runScript() and objectScript(), must run on the user interface thread since they _return_ a value to the binding, and property values must be delivered on the UI thread. (Swing requirement.)
