I’ve recently had several issues working with the perspective onStartup event.
The configure event menu is not always shown in the popup menu from the project browser. This generally rectifies itself on some unknown refresh event or restarting the designer.
Changes to the script are not always recognized. Particularly if a client session is open to the view. This may result in a ‘"Setting LastModification to “external”’ error in the log, followed by a forced self-merge. It has progressed to the point that I cannot make changes to the view at all now. Even if it says ‘saving’ the changes will all revert. Rebooting the gateway and restarting the designer did not help.
Cannot navigate/redirect to a new view in the onStartup event.
The view appears to be cached with the session, so navigating away and back again does not always fire the onStartup event. This may be a browser cache issue rather than a session cache issue.
I'll try to replicate, but what script? Can you break down what the script does? Is this just the navigate() call?
Should be working, but I'll look into it.
It depends on how the View is used in the "Page"; loading the View as part of a Carousel would keep it present in the Dom, whereas using it in an Embedded View would remove it - should the Embedded View point toward a different View.
It'll take me a long while to get back to you about these potential issues.
I was not able to replicate this at all with a Session open to the Pages/Views I was using. I have seen something similar if an OS has File Explorer/Finder open to Ignition directories while the Designer is open; do you happen to be hitting this scenario?
Worked perfectly for me on today’s build, even when chaining ViewOne > Navigate to ViewTwo > Navigate to ViewThree.
I tried navigating to a different Page (not View)) and then coming back, and the expected navigation chain fired again, which resulted in the expected View (ViewThree) being visible.
Could you upload your Views, and I’ll take a look to see what might be happening?
More info on #2: when I rebooted the gateway server, the content of the script reverted back to a point where it would not even compile, so it logs an error rather than attempting to navigate. Correcting the errors and saving shows ‘No changes to save’. The script will show the changes in the editor until the view is closed and re-opened.
After looking at the script you supplied, it looks like within the navigate call you are supplying a View name but attempting to do a Page navigation, as you’ve omitted the page/view/url argument name. When performing Page navigation, you must supply the configured page URL from the Page Configuration panel - NOT the name of the View you’re attempting to navigate to.
Assuming a configured url of /notauthorized for the ‘NotAuthorized’ View from the script, you’d want to supply ‘/notauthorized’ in the navigation call.
More info on issue #2 (event script changes not saving):
The view can be modified and saved if the event script is not modified.
Whitespace can be modified in the event script and saved
In general, modifications to the event script will prevent ANY change from the current view from being saved, regardless of whether the other changes are made before or after the non-whitespace change is made to the onStartup script.
On rare occasions, changes will result in an ‘Setting LastModification to “external”’ error, which will allow changes to be saved when merge/local is selected on the next save.
The onStartup and onShutdown scripts fire when making changes to the script. Certain actions/errors in the script seem to prevent the save action from completing successfully.
Example 1: I added a new perspective view, and added an onShutdown script with the line ‘system.perspective.refresh()’ in it. (In retrospect, that was a bad idea, I was attempting to see if the reference to the perspective library was related to the described behavior…) After saving initially, it refreshes. Now, I can’t modify the script…
Example 2: In order to test the code samples in the system.perspective.navigate documentation, I added a new perspective view, and added an onStartup script with the lines:
target1 = ‘/view-url’
target2 = ‘http://[server-name]:8088/data/perspective/client/[project]/view-url’
target3 = ‘View Name’
The view committed and saved as expected.
I modified the script by adding the line system.perspective.navigate(target) to the end with the following results:
target1: The view would not save. (This is the method I had been attempting when I created this thread)
url = target2: Error 403 when attempting to save
view = target 3: The navigation succeeded.
This is a valid issue, and I’ve opened an internal ticket. The issue you’re running into is that when you commit code for onStartup/oShutdown for a View, it shuts the View down, and starts it back up. Your script has a call to refresh, which sets a View back to its previous state. So when your View shuts down, its wiping any changes since the last save event which includes your changes to the onShutdown script. The end result is your script isn’t changing because your script told the View to toss out any changes when it shut down.
Copy your View JSON into a text editor (hold Shift and right-click the named View node - NOT the root node - and select Copy JSON)
Paste the contents of your clipboard into a text editor.
Locate the script which has the refresh call and very carefully remove that script object from the JSON
Copy the JSON from your text editor.
Paste the JSON from your clipboard BACK into the Designer (hold Shift and right-click the named View node - NOT the root node - and select Paste JSON)
This appears to be along the same vein as the other issue; the Designer is not built to perform most navigation or even perform some “basic” functions (have you tried opening a Popup in the Designer? Spoiler: it doesn’t do anything). View navigation is a bit different. So when you commit the script, it shuts down the View, sees the navigate call, knows not to do anything with it (effectively failing out of the script), and so you drop out of the script, straight into your previous version of the View.
Was item #4 ever resolved…I’m not seeing a resolution but hopefully I missed it?
I think I’m having a similar issue…onstartup fires every time if i navigate by clicking a component and using a navigation action of type=page, but it fails every time if I navigate by typing in the url or by using the horizontal menu component.
I’ve talked to support and they insist it is working as designed…
Thanks for looking at it @cmallonee…that’s interesting, because, if I understand ‘view navigation’ correctly, that’s the only case that works for me! If you have a way to trigger an event/script any time the URL changes, I think that is what I need…you’re using an onstartup event? I’m running 8.0.14 currently.
View navigation is something that I’ve never personally accepted as the “best” way to use Perspective, so I’m curious as to your use case. I’m not saying it doesn’t have its uses, but I’ve always felt that if you’re changing what’s being displayed to the user, then you’re displaying a different Page. I’m sure part of this comes from my previous experience in testing multi-page applications. Anyway, what URL change are you expecting? Are you just changing parameters, or is there a reason why you’re not building a different Page?
So it looks like I misspoke…I’m not using ‘view’ navigation, I’m using ‘page’ navigation in my navigation action. I am navigating to a parameterized view (/waterplant/annex/:filterTag) and here are the three scenarios I have:
–‘page’ navigation action on an onclick even…sets url to /waterplant/annex/F02 (for example), goes to the page, and fires the onstartup event seemingly every time (this is what I need)
–horizontal menu navigation…sets url to /waterplant/annex/F02 (for example), goes to the page, and usually does not fire the onstartup event
–type url or use bookmark…same as horizontal menu
Basically I’m looking to run a script anytime page navigation happens.
I think at least part of the issue is navigating from a parameterized view to the same view with a different parameter. So the url changes, but the view doesn’t reload(?) and the onstartup doesn’t fire.
If only parameters change, then the page will not reload.
Consider your Page to be a singleton, and parameters are the values used in the constructor of the singleton. There is special handling so that if your Singleton already exists, the values it holds are updated with the new param values being passed in. BUT, the Singleton is not deleted/removed/created - it is only updated with the new values. Since it is not being recreated, the onShutdown and onStartup are not executed again. If you were to navigate to an entirely different page and then navigate to the original page again, you would then see that the onShutdown and onStartup Events had executed.
There is no current avenue to run a script whenever Page navigation happens. You could place your own scripts whenever you TRY to navigate to a page, but if you're already on a page and only the params have changed, then you're not navigating to a page -you're only updating the param values.