# Trying simple dataset add, having script probelms

**URL:** <https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 16, 2024, 4:48pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330 "2024-01-16T16:48:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 4:48pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/1 "2024-01-16T16:48:46Z")

</div>

So one window, one text input, one drop down, and a timestamp. here is my code below:

```auto
ds = system.tag.read("[default]MyData").value

numbers = event.source.parent.getComponent('Text Field').text
dropselect = event.source.parent.getComponent('Dropdown').selectedLabel

newVal = ["numbers", "dropselect"]

system.tag.write("[default]MyData", system.dataset.setValue(ds, row, col, newVal))

# below is alternate ending, neither worked.
ds.data = system.dataset.addRow(ds.data, 0, newVal)

```

thanks in advance

dataset has one extra column for timestamp.

---

<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:** [January 16, 2024, 4:58pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/2 "2024-01-16T16:58:26Z")

</div>

Why are you trying to put a list (two values) into one specific cell of a dataset?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 4:59pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/3 "2024-01-16T16:59:02Z")

</div>

Some general tips when trouble shooting and asking for help on forums:

- reduce the example to the minimum. Don't introduce things that have nothing to do with the problem you're trying to solve: text fields, dropdowns... etc. Especially when you're not using them (`numbers` and `dropselect`)
- include the whole thing. You're using variables that are not declared in the code you posted (`row` and `col`)
- deconstruct the process and check things at every step.
- explain what you actually want to do. All we have to figure it out here is your code, which is not very descriptive, and if it's wrong then there's no way for us to really understand what it's supposed to do.  
The title says you want to add things, but nothing in the code actually adds anything.

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:00pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/4 "2024-01-16T17:00:38Z")

</div>

Thought that was what I needed to do reading on the forum.

i just have a text input box, drop down, and submit button.

when i submit I want a new row to be created with time stamp , text, drop down selection.

then I want to view that dataset in a power table.

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:04pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/5 "2024-01-16T17:04:02Z")

</div>

I am using numbers and dropselect though?

I thought row and col were generic? if I set row number will it add or overwrite?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 5:06pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/6 "2024-01-16T17:06:23Z")

</div>

Then you'll need `addRow`.  
Note that you'll probably need to supply a value for every column, which is why your attempt didn't work.

> [@Barbara\_Frumas](#):
>
> I am using numbers and dropselect though?

No you're not. Your `newVal` variable is a list with the literal strings `"numbers"` and `"dropselect"`, not the values from the variables.  
`row` and `col` have no special meaning.

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:08pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/7 "2024-01-16T17:08:45Z")

</div>

Can I supply a value for every col in the statement? or do I need a separate add for every col? couldn't find an example of multiple in one statement.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 5:10pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/8 "2024-01-16T17:10:09Z")

</div>

> [@Barbara\_Frumas](#):
>
> ```auto
> ds.data = system.dataset.addRow(ds.data, 0, newVal)
> 
> ```

Your `addRow` attempt might also have failed because of that `.data`. Is your `MyData` tag just a dataset tag ?

> [@Barbara\_Frumas](#):
>
> Can I supply a value for every col in the statement? or do I need a separate add for every col? couldn't find an example of multiple in one statement.

Just one call is enough. The function does what its name says: It adds a row.

---

<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:** [January 16, 2024, 5:10pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/9 "2024-01-16T17:10:47Z")

</div>

What you're looking for is `system.dataset.addRow()`

```auto
#get the original dataset value
ds = system.tag.readBlocking(['[default]MyData'])[0].value

#get the values from the components to insert in the dataset
#You will need to wrap them in a list.

numbers = event.source.parent.getComponent('Text Field').text
dropselect = event.source.parent.getComponent('Dropdown').selectedLabel

newRow = [numbers,dropselect]

#add row to dataset and write to the tag
system.tag.writeBlocking(['[default]MyData'],[system.dataset.addRow(ds,row=newRow)])

```

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:11pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/10 "2024-01-16T17:11:39Z")

</div>

its a dataset memory tag

Do i just newval1,newval2,newval3 ?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 5:13pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/11 "2024-01-16T17:13:06Z")

</div>

Here's an example that adds a row to a dataset:

```python
ds = system.dataset.toDataSet(
	['name', 'value', 'something'],
	[
		['foo', 21, 'a'],
		['bar', 12, 'b']
	]
)

ds = system.dataset.addRow(ds, ['pox', 42, 'c'])

```

Maybe it will help make things clearer ?

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:13pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/12 "2024-01-16T17:13:23Z")

</div>

> [@lrose](#):
>
> ```auto
> #get the original dataset value
> ds = system.tag.readBlocking(['[default]MyData'])[0].value
> 
> #get the values from the components to insert in the dataset
> #You will need to wrap them in a list.
> 
> numbers = event.source.parent.getComponent('Text Field').text
> dropselect = event.source.parent.getComponent('Dropdown').selectedLabel
> 
> newRow = [numbers,dropselect]
> 
> #add row to dataset and write to the tag
> system.tag.writeBlocking(['[default]MyData'],[system.dataset.addRow(ds,row=newRow)])
> 
> ```

I got

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 13, in <module>
TypeError: addRow(): takes no keyword arguments

```

---

<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:** [January 16, 2024, 5:14pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/13 "2024-01-16T17:14:47Z")

</div>

just remove the `row=`

May need to include 0 for the index.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 5:14pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/14 "2024-01-16T17:14:50Z")

</div>

> [@lrose](#):
>
> `system.dataset.addRow(ds,row=newRow)]`

remove the `row=` bit:  
`system.dataset.addRow(ds, newRow)]`

But you'll also need a value for the timestamp column

> [@lrose](#):
>
> May need to include 0 for the index.

nope it's optional. The function will append the new row to the end of the dataset if the row index is not provided.  
If you want the row inserted at the top or anywhere else, then indeed you'll need to provide the index.

---

<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:** [January 16, 2024, 5:18pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/15 "2024-01-16T17:18:47Z")

</div>

> [@pascal.fragnoud](#):
>
> nope it's optional. The function will append the new row to the end of the dataset if the row index is not provided.

Yeah, I know it's optional, but "generally", if an optional parameter is skipped then you need to provide the keyword argument which is why I included it. Kind of weird that it doesn't accept keyword arguments, that seems to go against the standard.

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/16 "2024-01-16T17:21:21Z")

</div>

> [@pascal.fragnoud](#):
>
> system.dataset.addRow(ds, newRow)]

```auto
timestamp = "[System]Client/System/CurrentDateTime.Value"

newRow = [numbers,dropselect,timestamp]

```

i get cannot coerce error on timestamp

---

<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:** [January 16, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/17 "2024-01-16T17:21:35Z")

</div>

Guess I missed the timestamp need as well.

Here is corrected code:

```auto
#get the original dataset value
ds = system.tag.readBlocking(['[default]MyData'])[0].value

#get the values from the components to insert in the dataset
#You will need to wrap them in a list.

numbers = event.source.parent.getComponent('Text Field').text
dropselect = event.source.parent.getComponent('Dropdown').selectedLabel

newRow = [numbers,dropselect,system.date.now()]

#add row to dataset and write to the tag
system.tag.writeBlocking(['[default]MyData'],[system.dataset.addRow(ds,newRow)])

```

---

<div class="post-metadata">

**Author:** ![Barbara\_Frumas](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barbara\_Frumas](https://forum.inductiveautomation.com/u/Barbara_Frumas)\
**Post date:** [January 16, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/18 "2024-01-16T17:23:05Z")

</div>

> [@lrose](#):
>
> ```auto
> #get the original dataset value
> ds = system.tag.readBlocking(['[default]MyData'])[0].value
> 
> #get the values from the components to insert in the dataset
> #You will need to wrap them in a list.
> 
> numbers = event.source.parent.getComponent('Text Field').text
> dropselect = event.source.parent.getComponent('Dropdown').selectedLabel
> 
> newRow = [system.date.now,numbers,dropselect]
> 
> #add row to dataset and write to the tag
> system.tag.writeBlocking(['[default]MyData'],[system.dataset.addRow(ds,newRow)])
> 
> ```

getting

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 13, in <module>
ValueError: Cannot coerce value '<java function now 0x2>' into type: class java.util.Date

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 16, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/19 "2024-01-16T17:23:42Z")

</div>

Because that's a string, not a timestamp.

If you want to get the value from a tag, you'll need to use one of the tag read functions:

```python
tstamp = system.tag.readBlocking(["[System]Client/System/CurrentDateTime.Value"])[0].value

```

or maybe use `system.date.now` to get the current time.

---

<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:** [January 16, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330/20 "2024-01-16T17:24:07Z")

</div>

You grabbed it before I corrected the `()` I left off of the `now()` function. Try again.

And also remove the comma at the end of the list, if you didn't already. That's what I get for going fast. uggh

[Next page](https://forum.inductiveautomation.com/t/trying-simple-dataset-add-having-script-probelms/84330.md?page=2)
