Data Passing Between Perspective Pages

Hello,

I have a few pages that I am able to navigate between with buttons. When the user presses one of the buttons, it should first grab selected rows from a table on that page and format them into a list. I then need access to that list to fill out another table on the next page.

I have tried doing this a few different ways without much luck.

The first being self.session.custom variables which I have verified are updating properly within the designer, but cannot seem to get it working on a browser instance. For the table on the second screen, I set up a binding to that same variable, but the table data comes up empty.

The second being view parameters with system.perspective.navigate and using the params flag to pass the object through. I populated the parameter as such:

selected = []
for row in tableData:
		# add row to new table
		if row.value.selected == True:
			selected.append(row.value)

	system.perspective.navigate('view2', params = {'view2Param': selected})

where view2Param is the parameter key on the targeted view.

Are there any other ways to do this or am I missing something probably obvious? Thanks in advance.

Have you tried message handlers?
https://docs.inductiveautomation.com/display/DOC81/Component+Message+Handlers

Message handlers won't work when you're changing pages

This is the best way to go about this, so your first consideration should be determining why you're having trouble getting it to work in a Session. Provide the code which does the write to the property, and show us the binding for the Table on the second page.

Now let's take a look at your code... It looks like a copy/paste issue, but the formatting is all wrong here. If it's just a pasting issue you can ignore this, but it looks like the supplied code would navigate after checking the 0th row in the table, whether that row is selected or not, and would not check any other rows.

It should have this indentation:

for row in tableData:
	# add row to new table
	if row.value.selected:  # check against a boolean value is redundant if row.value.selected is itself a boolean
	    selected.append(row.value)

system.perspective.navigate('view2', params = {'view2Param': selected})

You are right of course, i was mistakenly thinking about page scoped messages between views.

@cmallonee You're right on the second code snippet being a copy/paste issue. I fill out that selected list and then call system.perspective.navigate.

I agree that session variables seem the best way, but have had trouble debugging them. Is there a way to view the data held in them is the browser/session? Here's my technique for populating my session variable.

#clear previous selections
	self.session.custom.selectedDataTable= []	
	tableData = self.getSibling("tblResults").props.data
	
	for row in tableData:
		if row.value.selected == True:
# when we hit a selected row, append to session variable
			self.session.custom.selectedDataTable.append(row.value)
	
	system.perspective.navigate('/view)

image

It was as this point where I went for screenshots of a web session testing it, and it worked... I guess inquiring about it is the real solution. Thanks for the help!

I usually add a 'debug' button that system.perspective.print things, so I can see whatever I want in the browser console.

Quick thing about the code snippet presented here: Don't compare booleans to True or False. They're already True or False. Comparing them only results in... a boolean, which they already are.
if row.value.selected: is enough, and if the boolean's name is well chosen, it makes the condition read like english: "if something.selected" is very clear.

Note also that you could replace the explicit loop with a comprehension:
filtered_data = [row.value for row in tableData if row.value.selected]

Really ? I'd naturally tend to take the view params route for this kind of use cases.
I'm not a huge fan of putting everything in session props, especially when they're used in just one page.

The title is passing data between pages, which I had originally interpreted as two pages sharing data at the same time while both are open. If one page is open, and the intent is to navigate to a second page with some set of data, then yes, param passing is the way to go.

Was there any issues with this approach in certain versions? I'm working on a v8.1.18 gateway and have a programmer on v8.1.31, unable to get this to function with:

system.perspective.navigate(view = 'myView', params = {'myKey': 'myValue'})

I was able to pass between views using a session scoped custom parameter, but our initial thought was to use View parameters as the app navigates views within the same page. The key within the script was matched to the view parameter on 'myView'.