# Get an element from a row dataset only if the column exists

**URL:** <https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [December 12, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754 "2024-12-12T15:47:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [December 12, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754/1 "2024-12-12T15:47:43Z")

</div>

I have a dataset row.

Need to get a value from it. Currently doing this:

```python
start_time = row['STARTTIME']

```

However, for some reason, sometimes `STARTTIME` could not exist in the dataset, so that line throws an exception.

Anyone knows if there is equivalent function like `.get()` with a dictionary.  
Looking for something simpler that cehcking if the column exists.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [December 12, 2024, 4:10pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754/2 "2024-12-12T16:10:35Z")

</div>

You can use `system.dataset.getColumnHeaders(dataset)` to get a list of columns in the dataset.  
Try something like:

```python
# initialize start_time
start_time = 'na'
# get start_time if it is available
if 'STARTTIME' in system.dataset.getColumnHeaders(dataset):
	start_time = row['STARTTIME']

```

---

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [December 12, 2024, 4:14pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754/3 "2024-12-12T16:14:43Z")

</div>

I'm doing something really similar, looking for something simpler or cleaner like `.get`.

Thanks for the help anyway!

---

<div class="post-metadata">

**Author:** ![ryan.perretta](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.perretta/32/75110_2.png) [@ryan.perretta](https://forum.inductiveautomation.com/u/ryan.perretta)\
**Post date:** [December 12, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754/4 "2024-12-12T16:22:26Z")

</div>

[system.dataset | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-dataset)

The closest thing I know of to what I believe you are asking for are the `getColumnIndex(<column-name>)` function or `getValueAt(<row>, <column>)`.

In both cases if the column does not exist in the dataset a `java.lang.ArrayIndexOutOfBoundsException` will be thrown so you will still need to use a try/except block to catch it. But it would definitely work to check if the column exists.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2024, 4:23pm UTC](https://forum.inductiveautomation.com/t/get-an-element-from-a-row-dataset-only-if-the-column-exists/99754/5 "2024-12-12T16:23:21Z")

</div>

There's no safe get operator on Dataset or PyDataset.
