System.perspective.navigate doesn't work on session custom property tag change script

I am attempting to use the session prperty lastActivity to drive a session custom property that acts as an inactivity timer. That expression binding is working well and when displayed on a page the number is accurate. The expression fails to evaluate in designer but does evaluate correctly on any other session.

I then wanted to add a change script to this new custom property to navigate to the home page but that does not work. The script works when used on a button.

Since the error mentioned no perspective page attached to the thread, I attempted to also use pageId='/' as an optional parameter to system.perspective.navigate, but although that resolved the error on clicking save/apply it did not actually navigate to the page '/' as I was hoping. This syntax does not work on a button either. The manual page doesn't have an example of the optional parameter pageId, I'm looking to the community for help on formatting that correctly.

You're getting caught up in a common Designer vs. Session context issue.

In the Designer, there are no pages; the concept doesn't exist. But some pieces are dependent on a reference to pageId not being null, so we provide the View name as a placeholder within the Designer. IN a running Session, that pageId value is actually a unique value generated as each tab is opened.

Now, the Session has no idea which page of the potentially multiple you could have open that you want to navigate, so you'll have to manage that yourself.

  • Loop over every page of the session by making use of system.perspective.getSessionInfo() and filter the results based on the sessionId of this Session.
if currentValue.value > 2:
    all_sessions = system.perspective.getSessionInfo()
    for session in all_sessions:
        if session.id == self.session.props.id:
            page_ids = session.pageIds
            for page_id in page_ids:
                system.perspective.navigate(page="/", sessionId=session.id,  pageId=page_id)

You might also be able to do something like this:

if currentValue.value > 2:
    for page in self.pages:
        system.perspective.navigate(page="/", sessionId=self.id,  pageId=page.id)
4 Likes

Thanks! The first solution you proposed worked well for my application.

Is it possible to use your first code example on a Session Startup event?

I get a log error stating that global name 'self' is not defined. So I changed it to session.props.id and got object has no attribute 'props'.

Is there another way? thanks

It would probably work with some changes, but you're going to run into name collisions just trying to use it like it is because the supplied kwarg is session.

if currentValue.value > 2:
    all_sessions = system.perspective.getSessionInfo()
    for user_session in all_sessions:
        if user_session.id == session.props.id:
            page_ids = user_session.pageIds
            for page_id in page_ids:
                system.perspective.navigate(page="/", sessionId=user_session.id,  pageId=page_id)

can you help me with a same problem?

i want to open VIEW when a tag change value(boolean) but i cant do it , i tried with any examples of here but doesnt work

Welcome to the forum, Francisco.
For anyone to help you, you need to show,

  1. What you did. (Post formatted code - see Wiki - how to post code on this forum - and post a nicely cropped screenshot if you think that will be helpful.)
  2. What did you expect to happen?
  3. What happened? (Error messages, etc.)

Otherwise everyone is just guessing.

Tags are outside your project. Tags know nothing about your project. Tags don't know if your project is open or not. Tags know nothing about session properties in your project.

Try this:

  • Create a session custom property on your project.
  • Create a tag binding on that custom property.
  • Create an onChange event on that custom property. Put your navigation script in there.
2 Likes

That, and you got your indentation wrong, as the red squiggle is trying to tell you.

(post deleted by author)

the last point onChange event should be write on Expression??

im new on Perspective module the interface is totally different with Vision