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.

Thank you!

1 Like