How to pass the selected tab as a parameter

Before you get too rough with me, I have seen solutions for passing a parameter using scripting. This is more about finding a parameter that is unique to which specific tab has been selected. The "selectedTab" parameter is really the window that the tab points to, not a unique identifier of the tab itself. I have multiple tabs that point to the same window, but I want to pass a different parameter to that window based on which tab was selected by the user.

I'm reading this as 'Can I pass a parameter to a window from the tab strip?'

The answer, unfortunately, is no. At least, not as an out of the box answer.

It will still involve scripting (sorry), but it's not as bad as it seems.

Set the Navigation Mode to 'Disabled'. Add a pipe and parameters you want to pass to the window.
One of mine is Main Windows/WC Detail|{'line': 3425L, 'omron': True, 'idx': 1}

Add a propertyChange script to the tab:

import ast

if event.propertyName == 'selectedTab':
	windowName, paramString = event.newValue.split('|')
	params = ast.literal_eval(paramString)
	system.nav.swapTo(windowName, params)
2 Likes

Really, Jordan? Eeewwww!

Just use system.util.jsonDecode().

2 Likes

At the time I wrote it, system.util.json* didnt exist. :roll_eyes:

2 Likes

I don't think I asked my question clearly enough. I have seen similar scripting before, but this relies on each tab having a unique windowName. I have 6 tabs that all point to the same window. I need a parameter that tells me which of these 6 tabs has been selected. Why do I have 6 tabs pointing to the same window? Because they all represent the same type of data, and I want to use the tab number selected as a means of populating the same screen from a different data set.

I am relatively new to vision, so if the answer is to make a screen for each tab and use some kind of template to keep them all looking identical, I am open to that, but will need more information on the template concept.

Thank-you.

Jordan has pointed out that the built-in navigation in the tab component cannot do what you are after. You must disable the built-in navigation and do your own, so that you can include window parameters in that custom navigation. Jordan is recommending repurposing the "window name" property of each tab to contain both the target window name and JSON-encoded window parameters, which simplifies the custom navigation code. (Which he also supplied.)

You are free to write your own custom navigation, but you absolutely need custom navigation.

3 Likes

In each of these, the window name format is {window_name}|{parameters}



They all point to the same window, just the parameters are different.
The display names, of course all all different, because that is what the end user sees.

4 Likes

I just realized that you might not understand how window parameterization works in Vision:

  • Any root container property of a window is eligible to be treated as a parameter. Create custom properties on the root container with the desired names and data types.

  • Bind your window's components that need parameter-based initialization to the appropriate root container property. (Typically a uni-directional binding.)

  • In the navigation that will open the window, supply parameters as a jython dictionary. The keys of the dictionary must match the name of root container properties (case sensitive) for the values to be delivered.

3 Likes

Thank-you. Now I understand. I am not sure it will allow me to repurpose this filed. When I enter a value in this field I am presented with a drop-down list of windows. Is there a way around this?

Ignore the dropdown and just type what you need. (After changing the navigation mode to disabled.)

3 Likes

Thank-you. I think this will do exactly what I need.

Thank-you. I understood the custom properties, but did not realize there was any automatic matching of data based on jython key names. I will give this a try. I'm sure it is exactly what I am asking for, but may need some "play" time to fully understand the connections.

2 Likes

Update - this is working great, folks. I used jsonDecode. Really appreciate the help.

1 Like

Pssst! You should mark Jordan's first comment as the solution.

2 Likes