Get Row Index of Dataset Tag

I am using a dataset tag as a "lookup table" to change the background color of a label.

image

So I want to bind an expression to the backgroundColor of a label.

Here is some pseudo-code of what I am looking for (assume 'dataset' refers to the pictured dataset above):

subassembly = '720342'
rowIndex = getRowIndex(dataset,subassembly) //what is the syntax for this??
color = dataset(rowIndex) //backgroundColor would be bound to this value, and would be purple

How would I achieve this in an expression script?

Use this:

(Expressions are not scripts.)

3 Likes

Use a lookup() expression.

lookup({'path/to/dataset/tag'},'720342',color(250,250,251),'Subassembly','Color')
3 Likes

lookup() will also work a lot better if the dataset is sorted on the lookupColumn.

3 Likes

I should also say, that you may need to do some work to convert the java.awt.color type that you are providing into CSS compatible with perspective styling.

2 Likes

What would the syntax look like for my path to dataset tag? I've worked out some other issues and I'm still getting an error with this expression.

I used {'[edge]Subassembly_lookup'}

But every other time I've seen lookup() used in other examples, the dataset tag is specified by {Root Container ...}

You'll want to bind the dataset to a custom property on your view, then reference that property in your expression. While there's a way to directly reference a tag, it's slow and not recommended doing it that way.

1 Like

Is this related to your other post?

1 Like

yes

What is the syntax for referencing a custom property, specifically a dataset?

{path.to.component.customProperty}.

Consider browsing inductive university/the docs.

For a script the path is the same, just minus the curly braces and you use .getValueAt(row, col) to fetch a value, ie path.to.component.customProperty.getValueAt(0,12)

When building your expression, you'll be able to directly browse to it. The exact path/syntax you'll need varies depending on where you bind it, but if you put one on the view named myDS then it would be named {view.custom.myDS} in your expression.

If this is related to your other post, then as @pturmel posted over there, and here, 'lookup()' is part of the expression language, which is not the same as the Jython scripting that takes place in a tag value change script.

The syntax for referencing a property and/or a tag will vary based on context. I would highly recommend that you use the property/tag selector available in the editor dialog to select the property/tag you are interested in.

I feel like we’re missing a bit of context as to what exactly you’re having issues with and where you’re trying to accomplish it. The more detail you give us the better we’ll be able to help.

Start with the error message you’re getting.

3 Likes

I was able to succesfully use @lrose 's lookup expression after binding my dataset tag to a custom property in my view. I added a column to the dataset with the hex values for each color so they could succesfully be bound to backgroundColor in my label.

Thank you all!!!