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

**URL:** <https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542>\
**Category:** Ignition Early Access\
**Tags:** scripting\
**Created:** [March 22, 2019, 5:15pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542 "2019-03-22T17:15:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [March 22, 2019, 5:15pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/1 "2019-03-22T17:15:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 22, 2019, 5:41pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/2 "2019-03-22T17:41:20Z")

</div>

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?

> [@james.vosler](#):
>
> Changes to the script

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 22, 2019, 6:03pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/3 "2019-03-22T18:03:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [March 23, 2019, 2:53pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/4 "2019-03-23T14:53:25Z")

</div>

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”  
}  
}

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 25, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/5 "2019-03-25T14:41:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [March 25, 2019, 4:54pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/6 "2019-03-25T16:54:53Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [March 25, 2019, 6:20pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/7 "2019-03-25T18:20:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 25, 2019, 7:46pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/8 "2019-03-25T19:46:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [March 25, 2019, 8:07pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/9 "2019-03-25T20:07:52Z")

</div>

Additional note: For example 2, url method, using the code snippet in the documentation:  
system.perspective.navigate(url = ‘[docs.inductiveautomation.com](http://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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 25, 2019, 8:20pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/10 "2019-03-25T20:20:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![awalker](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awalker/32/6874_2.png) [@awalker](https://forum.inductiveautomation.com/u/awalker)\
**Post date:** [April 23, 2019, 6:17pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/11 "2019-04-23T18:17:20Z")

</div>

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

Thank you!

---

<div class="post-metadata">

**Author:** ![oisin.gribben1](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@oisin.gribben1](https://forum.inductiveautomation.com/u/oisin.gribben1)\
**Post date:** [May 29, 2020, 3:28am UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/12 "2020-05-29T03:28:20Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c313c728d3dc4124e6575cc23b69692319b0e7ca.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7d43315d66d16e5d63e983698046989ac52eb6c2.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 29, 2020, 4:08pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/13 "2020-05-29T16:08:00Z")

</div>

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.

 ![Screen Shot 2020-05-29 at 9.06.26 AM](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/37da339a55c1e82aec6685090b60ad95c3436d12.png)

---

<div class="post-metadata">

**Author:** ![garman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/garman/32/13346_2.png) [@garman](https://forum.inductiveautomation.com/u/garman)\
**Post date:** [July 20, 2020, 9:09pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/14 "2020-07-20T21:09:38Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 21, 2020, 3:10am UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/15 "2020-07-21T03:10:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![garman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/garman/32/13346_2.png) [@garman](https://forum.inductiveautomation.com/u/garman)\
**Post date:** [July 21, 2020, 1:37pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/16 "2020-07-21T13:37:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 21, 2020, 1:52pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/17 "2020-07-21T13:52:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![garman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/garman/32/13346_2.png) [@garman](https://forum.inductiveautomation.com/u/garman)\
**Post date:** [July 23, 2020, 7:59pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/18 "2020-07-23T19:59:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![garman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/garman/32/13346_2.png) [@garman](https://forum.inductiveautomation.com/u/garman)\
**Post date:** [July 23, 2020, 9:42pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/19 "2020-07-23T21:42:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2020, 10:24pm UTC](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542/20 "2020-07-23T22:24:09Z")

</div>

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.

> [@garman](#):
>
> Basically I’m looking to run a script anytime page navigation happens.

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.

[Next page](https://forum.inductiveautomation.com/t/bug-13300-13302-16835-perspective-view-onstartup-problems/23542.md?page=2)
