# Get Row Index of Dataset Tag

**URL:** <https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [September 26, 2024, 6:56pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512 "2024-09-26T18:56:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [September 26, 2024, 6:56pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/1 "2024-09-26T18:56:09Z")

</div>

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f0f58b5ffe9db68a12cfa53cbb8f151abb128e8e.png)

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):

```python
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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 26, 2024, 7:29pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/2 "2024-09-26T19:29:32Z")

</div>

Use this:

> **[lookup | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/logic/lookup)**
>
> This looks for lookupValue in the lookupColumn of dataset.

(Expressions are **not** scripts.)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 26, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/3 "2024-09-26T19:30:36Z")

</div>

Use a `lookup()` expression.

> **[lookup | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/logic/lookup)**
>
> This looks for lookupValue in the lookupColumn of dataset.

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

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 26, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/4 "2024-09-26T19:30:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 26, 2024, 7:34pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/5 "2024-09-26T19:34:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [September 30, 2024, 8:46pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/6 "2024-09-30T20:46:45Z")

</div>

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'}

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/5/1566e849ec1c96277900ab19ceaa8d585ffe4e51.png)

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

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 30, 2024, 8:49pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/7 "2024-09-30T20:49:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 30, 2024, 8:51pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/8 "2024-09-30T20:51:35Z")

</div>

Is this related to your other post?

> [@Issue with lookup() in tag change script](https://forum.inductiveautomation.com/t/issue-with-lookup-in-tag-change-script/96629):
>
> I'm trying to use lookup() in a tag change script to assign a string value to a memory tag based on the results of a lookup in a dataset tag. My script is showing an error in the Ignition gateway and is not running. I suspect it is a syntax error with the way I am referencing the dataset tag. I tried running the script with line 3 commented out (and writing a random value to dl\_fx instead of 'dl\_ID\_line1'), and the script was able to run fine. For context, [edge]CLICK\_values/Line1/DL\_ID is eq…

---

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [September 30, 2024, 8:57pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/9 "2024-09-30T20:57:15Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [September 30, 2024, 8:57pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/10 "2024-09-30T20:57:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [September 30, 2024, 9:28pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/11 "2024-09-30T21:28:33Z")

</div>

`{path.to.component.customProperty}`.

Consider browsing inductive university/the docs.

> **[Expression Language and Syntax | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/expression-language-and-syntax#dataset-access)**
>
> Expression Language

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)`

> **[Datasets | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/python-scripting/variables-datatypes-and-objects/datasets#accessing-data-in-a-pydataset)**
>
> Datasets and PyDatasets

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 30, 2024, 9:28pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/12 "2024-09-30T21:28:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 30, 2024, 9:29pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/13 "2024-09-30T21:29:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [September 30, 2024, 9:38pm UTC](https://forum.inductiveautomation.com/t/get-row-index-of-dataset-tag/96512/14 "2024-09-30T21:38:37Z")

</div>

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!!!
