[Question] Perspective - Binding Query Parameter to Component

I am trying to bind the value property on a SQL query binding to a dropdown value in a view on a different page. I have tried many different syntax’s and don’t seem to be getting it. It this possible? If so, what would the syntax be?

Basic steps I am looking for is to run query and return list to dropdown on a landing page, choose from list, click button and pass selected value from dropdown to query and on to an XY chart.

Thanks in advance for any information.

Dropdown and Button to switch pages

Query Binding

I’m not entirely sure I understand your question. What are your screenshots attempting to show us?

You have the literal value 1541429562 entered as the parameter value in your binding. You want that dropdown’s value in there? Can you not browse to in via the UI beneath that fx button?

I put the literal value in to test the query. Components on other views do not show up when you use the fx button.

Only session and current view items show up.

  1. It is not possible to access components in other Views in any way within Perspective. This is because the only Views that “exist” within the Session scope are Views which are currently displayed in an open Window/Tab. So binding to a View which is not open would result in your bindings failing. If you absolutely MUST have the dropdown on a different Page, then you should have an onChange Script for Dropdown.props.value which writes the value to a Custom Session variable.

The attached View does what you’re trying to accomplish albeit with a local Label instead of an XY Chart - you’re on your own to determine how to take what I’ve given you and apply it to your use case. I would recommend that instead of sending the new value to Label.props.text, that you assign a custom property on the XY Chart to hold the value.

TabulaRasa.json (1.9 KB)
To use this view, open the file in your preferred text editor, copy ALL content to clipboard, Create a new View in your Designer, right-click the View node (not the root node) and select “Paste JSON”.

Pieces to examine:

  1. The Dropdown.props.options is bound to a Named Query I have locally which executes the following SQL: select name from beverages, where beverages is a table with various beverages we keep stocked on site, and name is… well, the name of the beverage. It’s very important that you note that the query uses the word “name”, becase we’ll need it for part 2.

  2. The Dropdown binding also has a Script Transform as part of the binding, which “massages” the returned data into something the Dropdown can use. To extract the actual returned value from the Named Query, you’ll want to reference it by what you requested, in my case it was ‘name’. If your query is select value from my_table, then you’d use row['value'] to extract your data. The transform uses the following script to iterate over the returned Dataset object:

option_list = []
py_value = system.dataset.toPyDataSet(value)
for row in py_value:
    option_list.append({'label': row['name'].upper(), 'value': row['name']})
return option_list
  1. The final piece is on Dropdown.props.value. If you look at the property, you’ll see that it has an onChange Script attached to it (see the “page” icon to the right?). If you right-click Dropdown.props.value, and select “Edit Change Script…” you can see that I’m setting my Label’s text to whatever the newest selected value is.

Thanks for the suggestions.

I did get it working the way I envisioned using the edit change script on the value writing to a mem tag and then picking up the mem tag in the parameters part of the query.

You’ll want to be careful in writing that value to a tag, if your XY Chart is then reading from the tag.

Session properties would adjust the XY Chart for the individual Session, while writing/reading the value to and from a tag will result in one user changing the displayed data in the XY Chart for ALL users who are viewing that XY Chart.

2 Likes

I see.

Is there an example of the scripting functions for writing to properities related to Perspective?

There’s some in the 8.0 Documentation, but you’d most likely just want to place the following in your onChange script:

self.session.custom.propertyName = currentValue

That is what I had to do for my project also.

It is kind of like Vision ‘Client Tags’ == Perspective ‘session.custom.propertyName’

Are paste Json and see the “page” icon to the right of property enable in the Trial Version?

Yes, the trial version should be able to paste JSON content and see the onChange Script icon - there should be nothing preventing you from seeing them.

Please note that to see the “Copy JSON” and “Paste JSON” options, you must be holding Shift, and you must be right-clicking a View node (not the root node).

Also, please note that the page icon does not denote that a Component has an attached Script, rather, the icon denotes that the individual property has an onChange Script which will execute whenever the property’s value changes.

1 Like

The paste JSON has worked fine for me when following those details:

1 Like