Pass Parameter between pages

What way is used to pass parameters between pages in 8.0

I’m going to break my answer into two pieces because there’s a lot of confusion around the terminology between Views, Pages, Windows, and Sessions. To be clear, Windows are Vision, so I won’t be tackling that here. The only way to pass values between sessions is either through the database or Tags, so we’ll gloss past that as well.

Part One - Passing Values Between Views:

To pass a parameter to an Embedded View, create a new EmbeddedView.props.params property for each key you’d like to send. This key must be identical to the parameter the Embedded View will be expecting. In the case of the following screenshot, the Embedded View is expecting a parameter with a key of “id”.

Carousel Views are handled in the same manner, although the properties you’ll be configuring are called “viewPath” and “viewParams” instead of “path” and “params”.

Popup Views have their parameters configured in the Popup Action screen. In the following screenshot, my Popup View expects three parameters: “id”, “enable_button”, and “parent_count”. With Popup Views, you may only supply parameters to be read by the “child” View; there is no back-and-forth communication between the child and parent Views.

1 Like

Part Two - Passing Values Between Pages:

Something important to understand about “Pages” in Perspective is that they are simply Views which can be navigated to via a URL. So, just like Views, if they are not currently open in a browser tab then they don’t exist as part of the Session. Due to the uncertainty of the Session as to whether or not a Page is open (the Gateway knows what is open and where, but a user’s Session has no knowledge of any of that), you can not “pass” a parameter between pages. On top of that, if you have two tabs open to the same “page”, they both have a unique ID, so who would you be sending the message to?

But, this doesn’t mean you can’t use the Session to do everything you need.

How To Do It:

The best way to send values from one “page” to another is to use a Session Custom property. Use a script on MyPageAlpha to set self.session.custom.myProp, and make sure that MyPageBeta is binding (probably bi-directionally) to that same property.

Alternatively:

If and only if you absolutely know that you will have two tabs open and MyPageGamma is open in one tab, and MyPageDelta is open in the second, you could use the following code on MyPageGamma to “broadcast” a message.

system.perspective.sendMessage(messageType='UniqueBroadcastNameHere', payload={'quasi_unique_key':'desired_value'}, scope='session')

You would then want the component on MyPageDelta to have a configured Script which “listens” for the broadcast at the session scope with the following code waiting to execute:

self.custom.my_value = payload['quasi_unique_key']

I’ll work on getting a View set up to add to this thread so that you can see message handling in action.

@cmallonee
Thanks for your detailed reply.
I have tried the part with setting the session propert which I have attached below in a screen shot.
The property doesn’t seem to be changing.

Sorry, that answer could have been more clear - I’ll update it.

Scripts have no concept of “session”; you must reference session from the context of the component. Please try:

self.session.custom.tagPath = "Testing"

@cmallonee
I made the chnages and still no change in the properties.
I noticed that in the error logs i get this error everytime I click the button to navigate to the new page.

Are you using an onClick Event to do both a Script Action and a Navigate Action? If so, there is a known issue around chaining those two actions in one event.

If you are not, please Save your project and restart your Designer. You should also consider closing out any open Sessions, waiting for them to expire on the Gateway (120 seconds), and then you can try again.

Yes I am doing both. That must be the issue.

Potentially…

The current workaround is to perform the navigation as part of your script action.

You should include system.perspective.navigate(page='/my/page/url') as the final part of your script.

Check out the documentation if you need assistance with the method.

BetaDemo.proj (28.1 KB)

This should provide a basic overview of how to use sendMessage().

2 Likes

Is there a way to get the screenshot reloaded? Or is this documented anywhere yet in the manual? I'm starting to explore it and I'm struggling to get my parameter to get passed from the parent to the child.

We’re working on resolving the other screenshots mysteriously disappearing, but this should help in the meantime.

Available params already defined by the specified View are visible by clicking the + icon:

Choose what params you want to specify bound/assigned values for (you can either hard-code values or bind to an existing property at the session or View level):
39%20PM

You can perform the same parameter passing in a script:

	popup_id = 'a-unique-id'
	view = 'ParamViews/ParamView'  # path relative to the "Views" directory, with no leading slash.
	param_dictionary = dict()
	param_dictionary['param_one'] = '1'
	param_dictionary['param_one'] = 'and 2'
	param_dictionary['param_one'] = self.props.text
	system.perspective.openPopup(id=popup_id,view=view,params=param_dictionary)
1 Like

2 posts were split to a new topic: Popup Views Fail To Interpret Parameters Which Are Objects