Hello! I’m trying to use system.perspective.navigate on a Session Startup event. Essentially I’m looking at specific attributes of the user and letting them either pass through to the main view or directing them to an option select view.
You’re not able to navigate from Session Startup, because that event fires/executes before any Perspective Pages (and the framework they need for navigation) is provided to the session. This is most easily recognized when you attempt to access a project which requires authentication; you have to go through all of the authentication steps before you’re on a Perspective View, but the Session Startup event fired as soon as your browser accessed the login page.
If you move this script to the View Startup Event for the View that a user would land on if you were NOT to do the navigation, then it should work as you’re written it (assuming all other logic steps are correct).
Essentially, you’ll notice that the Session Startup script has only a session parameter, while the View Startup has self and event. So the Session Startup Script has only the attributes and methods available to the “Session”, while the View Startup Script has methods and attributes available to “Views” (self), and the “event” which triggered the View startup.
Let me preface this by saying I’m converting a Vision project to Perspective (slowly but surely). So some of the way things work (or the way I’m thinking about them) comes from the Vision world.
Essentially I have a shared application, with a user having anywhere from 0 to 10 plants assigned to them. I had a client tag that was populated with the list of plants authorized to that user. In the Perspective world, I simply created a session custom property (as I’d be referencing this list across several views). So my thought was that, on startup, to check if a user has multiple plants assigned to them and if so, redirect them to a plant selection screen.
All of that said, I think I simply need to have the startup event set a ‘selectedPlant’ flag to false, and then add a startup event to each view to redirect to plantSelect if it the ‘selectedPlant’ flag is false (and obviously set it true when a plant is selected).
That does lead me to aquestion - is there something more efficient than creating a startup event check for each view/page?
Before you do ANY of that, why don’t you explain what you’re trying to accomplish/replicate from Vision?
From what I’ve been able to piece together, it sounds like users have “plants” assigned to them or available to them. If they have any number of plants greater than 1, they need to select one form their list. If they have only one, then they should go to that plant. If they have no plants available, then there is some other un-described logic which takes place.
Best Guess Project Construction Based On Only What I Have In Front Of Me:
Create a View which allows the user to select form among their available plants. Create a View Startup Script for this View which checks to see if the user has only one plant. If so, then navigate to that plant’s page. If the user has no plants, then navigate to somewhere else.
Yes - your summary is correct. The ‘infinite loop’ I was concerned about earlier was that if a user changed views and then navigated back to the main view, the startup logic would run again. Or if a user directly accessed a view URL without a selected plant, they would need to be redirected to the plant selection view. I think that is all resolved by conditioning the startup logic on whether a plant is selected or not, in addition to the plant count.
I was just hoping that instead of adding a startup script to each view that there would be a more elegant way.
There is always a more elegant way, but it also usually takes more effort.
Instead of worrying about all of this navigation logic, make two Views.
ViewA is a template View which displays everything you need for a plant.
ViewA should take the plant name or id as a parameter.
Put EVERYTHING you would put into a plant’s page in this View.
View B is essentially nothing more than a dropdown which is populated with the plants available to the user, along with an Embedded View.
Bind the Embedded View’s path to be that of ViewA, and bind the passed parameter to the value of the dropdown.
If you want to default the visible plant to the first available plant for a user, use some logic to determine if the Dropdown has at least one option, and if so set Dropdown.props.value to Dropdown.props.options.
Doing this would allow you to provide one page which allows for
Picking the displayed plant
Based off of the plants available to a user
Without navigation based logic
While preventing a user who has no available plants from seeing any
And defaulting to the “first” available plant.
Something that I’m seeing a lot of users doing is taking projects which were built in Vision and just porting them over to Perspective. Many times, however, these Vision projects were designed in a certain way because of limitations elsewhere. Perspective provides SO MANY avenues for crafting a project that it can be overwhelming. If you find yourself thinking “there has to be a way to do this better…” then there probably is.