Multiple scripts on a single button event

I have looked through the forum and the user manual and can’t seem to find any information on this, is it ok to have two scripts run on an onActionPerformed Action in perspective?

You can configure several actions, of which there may be multiple scripts, but you must understand that the Actions are executed asynchronously and with no guarantee of order. Due to this, you should have no dependencies amongst the scripts, and there are some scripting functions I do not recommend be used if you are to use multiple scripting actions, including .navigate, .closeSession, and .logout.

I recommend against using those actions because they will change the state of the page/session in a way that could easily cause other scripts which rely on page information (including component values) to fail.

Consider the following example:
I have two script actions under one Event. One of the actions navigates to another page. The second action reads a tag value and then writes to another tag based off of the tag value and the value of a sibling dropdown.

When theses are run async, there’s every possibility that the navigate action will complete first. When that happens, my Perspective Page is now a different page, and so the references in the second script will fail when they attempt to locate the sibling dropdown.

This problem is not confined to script actions; any actions “queued” under one event could result in similar behaviors.

Examples which should not cause issues include anything that does not change the state of the session or the Page.

1 Like

Thank you!

1 Like

I think this is what I ran into while trying to navigate to a view, with a onClick event script, while also trying to transfer a custom name property to a label enclosed in the view through message handling.

The weird thing is that in “preview mode”, upon clicking the button, the custom name property is successful in being transferred to the label that had the message handler set up in the “navigated view”.

What would you recommend doing in the case that I would like to click on a icon to navigate to a screen as well as have a custom property of the button clicked be broadcast to a message handler on the view being navigated to.

For example, I want to click on a valve icon and then have a valve view be navigated to, which updates its title based upon the valve clicked upon.

Preview mode in the Designer never does navigation, never hears message handlers, and never opens popups, so I’m not sure how to explain your partial success.

I would avoid using a message handler and send the value as a param:

Configure a Navigation action for your Icon.

Screen Shot 2021-07-28 at 6.23.48 PM

Configure a page URL which expects a parameter be supplied. Don’t forget to specify the correct View for the “Primary View” value.

Screen Shot 2021-07-28 at 6.24.12 PM

On the named View node you want to open, make sure to place an expected param and supply a default value.

Screen Shot 2021-07-28 at 6.24.30 PM

Using these steps, clicking my Button (Icon in your case) navigates to the supplied page and passes the string “ParamValue” to the param named first.

Question
How about system.tag.writeBlocking - Ignition User Manual 8.0 - Ignition Documentation (inductiveautomation.com) and system.tag.readBlocking - Ignition User Manual 8.0 - Ignition Documentation (inductiveautomation.com)
Isn’t this like blocking the script before it continues to the next line?

@jespinmartin1 Your usages would be in one script. The original post was for more than one script attached to a single event. If those two usages were in separate scripts, then they would not prevent the other from executing because they would each be on their own thread.

ohhh ok, thanks a lot.

To contribute: I’ll just like to share an idea of how I would make some event happens in a specific order. But it “might” have some limitations.

  1. Move all your multiples events into custom methods
  2. Instead of having various events, just create one, necessarily a script event.
  3. Call your methods in desired order.

Something like this


It will always execute in that exact same order.