Perspective - navigate on startup

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.

                onlyPlants = ['Plant 1','Plant 2','Plant 3'] 
                session.custom.plantSelect.plantList = onlyPlants
		if len(onlyPlants) == 1:
			session.custom.plantSelect.plantNumber = onlyPlants[0]
		else:
			session.custom.plantSelect.plantNumber = -1
			session.custom.plantSelect.divison = ''
			session.custom.plantSelect.plantName = 'No Plant Selected'
			system.perspective.navigate(view = '/plantSelect')
                        #system.perspective.navigate(view = '/plantSelect',sessionId = session.id)

I’m getting the error ‘…No perspective page attached to this thread.’

Any thoughts on what I’m missing?

Thanks!
Tim

What version are you on? This sounds like a bug that was fixed fairly recently.

Hey Paul - I’m running:
Version: 8.0.2 (b2019060511)

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.

1 Like

Thanks for that, even though it’s not what I wanted to hear. I’ll have to change the way I was thinking about this, as it would be a bit of an endless loop.

Thanks!

If you could elaborate on how it would be an endless loop, we might be able to help you defeat infinity.

3 Likes

Could your start up to a company branded logo page or something then trigger a timer script to do what you are wanting to do ?

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.

  1. Instead of worrying about all of this navigation logic, make two Views.
  2. ViewA is a template View which displays everything you need for a plant.
  3. ViewA should take the plant name or id as a parameter.
  4. Put EVERYTHING you would put into a plant’s page in this View.
  5. View B is essentially nothing more than a dropdown which is populated with the plants available to the user, along with an Embedded View.
  6. Bind the Embedded View’s path to be that of ViewA, and bind the passed parameter to the value of the dropdown.
  7. 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[0].

Doing this would allow you to provide one page which allows for

  1. Picking the displayed plant
  2. Based off of the plants available to a user
  3. Without navigation based logic
  4. While preventing a user who has no available plants from seeing any
  5. 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.

3 Likes

I’ll have to play around with this concept a bit, particularly around embedded views. I’d like to flesh out the skeleton of the project to see if I’ve got any further questions.

Thanks for the help!

1 Like