[Bug-13300,13302,16835]Perspective View onStartup problems

I’ve recently had several issues working with the perspective onStartup event.

  1. 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.
  2. 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.
  3. Cannot navigate/redirect to a new view in the onStartup event.
  4. 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.
  1. Known issue already being tracked.
  2. I'll try to replicate, but what script? Can you break down what the script does? Is this just the navigate() call?
  1. Should be working, but I'll look into it.
  2. 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.

  1. 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?
  2. Worked perfectly for me on today’s build, even when chaining ViewOne > Navigate to ViewTwo > Navigate to ViewThree.
  3. 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.

{
“custom”: {},
“events”: {
“system”: {
“onStartup”: {
“config”: {
“script”: “\t#\tshared.Common.Util.logInfoPrint(“LimitedAccess”, self.session.props.auth.user.userName, type(self.session.props.auth.user.roles).name, self.session.props.auth.user.roles)\n#\tuserName \u003d system.security.getUsername()\n\tuserName \u003d self.session.props.auth.user.userName\n\tuser \u003d system.user.getUser(“default”, userName)\n\n\n\tfound \u003d False\n\t\n\tif user is not None:\n#\t\tuserRoles \u003d self.session.props.auth.user.roles\n\t\tuserRoles \u003d user.getRoles()\n#\t\tx\u003dlist(self.session.props.auth.user.roles)\n\t\tshared.Common.Util.logInfoPrint(“LimitedAccess”, user.getRoles())\t\n\t\n\t\tif userRoles is not None and len(userRoles) \u003e 0:\n\t\t\tfor role in userRoles:\n\t\t\t\tif role.value \u003d\u003d \u0027NobodyHasThis\u0027:\n\t\t\t\t\tfound \u003d True\n\t\t\t\t\tbreak\n\n\tif not Found:\t\t\n\t\tsystem.perspective.navigate(\u0027NotAuthorized\u0027)\n\t\t”
},
“enabled”: null,
“permissions”: {
“securityLevels”: [],
“type”: “AllOf”
},
“scope”: “G”,
“type”: “script”
}
}
},
“params”: {},
“permissions”: {
“securityLevels”: [
{
“children”: [],
“name”: “Authenticated”
}
],
“type”: “AllOf”
},
“propConfig”: null,
“props”: {},
“root”: {
“children”: [
{
“meta”: {
“name”: “Label”,
“rotate”: {
“angle”: 45
}
},
“position”: {
“height”: 403,
“width”: 579,
“x”: 109.3105697631836,
“y”: 153.3105697631836
},
“props”: {
“alignVertical”: “center”,
“style”: {
“color”: “#FB7942”,
“fontSize”: “72px”
},
“text”: “Congratulations!”
},
“type”: “ia.display.label”
}
],
“meta”: {
“name”: “root”
},
“type”: “ia.container.coord”
}
}

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.

Re: #3 navigation from onStartup event: I agree - the parameter was missing the forward slash. Issue #4 had me believing that it was running script that apparently it had never saved (issue #2).

More info on issue #2 (event script changes not saving):

  1. The view can be modified and saved if the event script is not modified.
  2. Whitespace can be modified in the event script and saved
  3. 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.
  4. 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.

Example 1:
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.

Workaround:

  1. 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)
  2. Paste the contents of your clipboard into a text editor.
  3. Locate the script which has the refresh call and very carefully remove that script object from the JSON
  4. Copy the JSON from your text editor.
  5. 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)

Example 2:
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.

Additional note: For example 2, url method, using the code snippet in the documentation:
system.perspective.navigate(url = ‘docs.inductiveautomation.com’)

This results in a 404 error. Because the url does not start with ‘http://’ (et al), it get’s prefixed with a relative view url path, resulting in a bad url.

Yah, that’s more of a documentation issue, but I’ll let them know. They’ve fixed it.

The tickets associated to these issues have been fixed as of 4/10.

Thank you!

Hi, we are still getting this error on edge version: 8.0.11
we have a startup script that checks if the user is logged in and forces them to login if not.
steps:

  1. Navigate to page via url with no user logged in - script is triggered

  2. Log out

  3. Navigate to the page via url from the login page without logging in - scripts is not triggered


You’er using a System-level onStartup Event. You want to use the View-level onStartup Event. Right-click the View node in the Project Browser, then select Configure Events.

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…

It worked for me while using the url, BUT… I was able to replicate the issue if performing just View navigation. I’ve opened an internal ticket to address the issue.

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.