Trying to get datapoint from dataset binding on custom property

I have a custom prop with a query binding, returns 1 row and 70 columns. In a button event script, I would like to get a value at [0,2], etc.

I attempted to follow advice on this thread: https://forum.inductiveautomation.com/t/bind-text-property-of-vision-label-to-tag-dataset-value/51197

But can't seem to get it to work.

Here is the code:

value = u'{$\.sp_data}[0,3]'
#value = u'{$\.sp_data}'
#system.tag.writeBlocking(['[default]Testing Tags/Demaris/PS01_Setpoint.value'], [value])
print value

Neither of the value= statements returned a value. The print result was simply the value string: {$\.sp_data}[0,3] or {$\.sp_data}.

What am I missing here?

You are confusing the expression syntax for accessing a value in a dataset with the python syntax for accessing data in a dataset.

For python you need to do yourDataset.getValueAt(0,2), or if its a pyDataset, yourDataset[0][2].

You'll also need to fetch the dataset data, right now value is just a string with a value of {$\.sp_data}[0,3]. The proper path to fetch the dataset would look something more like myDataset = event.source.parent.sp_data.

To work correctly then, your script would look something like

myDataset = event.source.parent.sp_data
myValue = myDataset.getValueAt(0, 2)
system.tag.writeBlocking(['[default]Testing Tags/Demaris/PS01_Setpoint.value'],[myValue])

If you have the script editor open for the event, on the right side near the top you should see a tag icon and an icon that looks like a list above that. If you click that list icon, you can traverse the components in your view to be able to find and reference the component property with your dataset.

2 Likes

Right you are! Those subtle differences between expression and python... :man_facepalming:

I started this script off using the Set Tag Value builder. That's what gave me the value = u'{$\.sp_data}'.

Thank you, Ryan!