# addRow to Dataset

**URL:** <https://forum.inductiveautomation.com/t/addrow-to-dataset/86026>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 20, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026 "2024-02-20T15:24:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 20, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/1 "2024-02-20T15:24:49Z")

</div>

Hello  
I'm trying to add a new row to a Dataset. I've already checked in this forum. But I'm not able to find the solution  
This is the code:

```auto
uno = self.parent.getChild("bin_flex").getChild("Table")
newrow = [0,1,2,3,4,5,6,7,8]
uno.data = system.dataset.addRow(uno.data, newrow)

```

I'm getting this error

```
caused by org.python.core.PyException

```

Traceback (most recent call last):  
File "function:runAction", line 4, in runAction  
AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'data'

this is the data in the table  
{  
"$": [  
"ds",  
192,  
1708442623499  
],  
"$columns": [  
{  
"name": "fut\_id",  
"type": "Integer",  
"data": [  
10408  
]  
},  
{  
"name": "bin\_no",  
"type": "String",  
"data": [  
"8001202300005555"  
]  
},  
{  
"name": "plate\_no",  
"type": "String",  
"data": [  
"A0"  
]  
},  
{  
"name": "real\_cast\_no",  
"type": "String",  
"data": [  
"1"  
]  
},  
{  
"name": "apm\_park\_name",  
"type": "String",  
"data": [  
"E"  
]  
},  
{  
"name": "cast\_date",  
"type": "String",  
"data": [  
"05/23"  
]  
},  
{  
"name": "extraction",  
"type": "String",  
"data": [  
"extraction"  
]  
},  
{  
"name": "flask\_status",  
"type": "String",  
"data": [  
"Extracted"  
]  
},  
{  
"name": "delete",  
"type": "String",  
"data": [  
"delete"  
]  
}  
]  
}

please let me know  
Thanks

---

<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:** [February 20, 2024, 3:34pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/2 "2024-02-20T15:34:58Z")

</div>

Perspective components segregate their properties into groups, unlike Vision. So it should be `uno.props.data`, not `uno.data`.

{ You should use the forum comment editor's "preformatted text" button for tracebacks and pasted json, too. Not just code. Use the pencil icon on your post to fix the formatting. }

---

<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:** [February 20, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/3 "2024-02-20T15:58:40Z")

</div>

Also, lots of your dataset columns are strings, which may or may not allow the raw integers you're supplying to actually pass in as new row data.

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 20, 2024, 4:51pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/4 "2024-02-20T16:51:44Z")

</div>

Thanks a lot. I'll try this and let you know  
Also sorry for the formatting!

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 20, 2024, 4:52pm UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/5 "2024-02-20T16:52:07Z")

</div>

Yep I know, I was just trying to push some different error 😃

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 21, 2024, 8:20am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/6 "2024-02-21T08:20:29Z")

</div>

> [@Francesco\_Vittadini](#):
>
> ```auto
> uno = self.parent.getChild("bin_flex").getChild("Table")
> newrow = [0,1,2,3,4,5,6,7,8]
> uno.data = system.dataset.addRow(uno.data, newrow)
> 
> ```

thanks it works perfectly ... such a small modification ... 😄

---

<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:** [February 21, 2024, 8:23am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/7 "2024-02-21T08:23:15Z")

</div>

But... that's the same code as in the initial post ?

tip: `range(9) == [0, 1, 2, 3, 4, 5, 6, 7, 8]`

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 21, 2024, 9:00am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/8 "2024-02-21T09:00:20Z")

</div>

Yup it was working even with int value ... Now I have another problem which I think is related to the data format I want to add  
the new row is generate from a query .. this is the result

```auto
[{"fut_id":16366,"bin_no":"8001202300011546","plate_no":"H7","real_cast_no":"30","apm_park_name":"B","cast_date":"09/23","extraction":"extraction","flask_status":"Extracted","delete":"delete"}]

```

when I try to add it says:  
IndexError: Number of values (1) in row 1 doesn't match number of columns (9) in dataset.

How can I solve this?  
Thanks again

---

<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:** [February 21, 2024, 9:07am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/9 "2024-02-21T09:07:47Z")

</div>

Are you trying to pass it as is ? Because that's a list containing ONE element: a single dict, which itself contains 9 key/value pairs.

I'd do it like this:

```python
ds = self.parent.getChild("bin_flex").getChild("Table").props.data
newRow = your query here
newRow = [newRow[0][col] for col in ds.columnNames]
self.parent.getChild("bin_flex").getChild("Table").props.data = system.dataset.addRow(ds, newrow)

```

The third line is here to make sure things are in the right order.  
That's assuming the dict keys match the column names in your dataset.  
If they don't you'll need some way to sort your list of values to match the dataset's columns.

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 21, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/11 "2024-02-21T09:18:16Z")

</div>

Hello Pascal  
seems like there is a problem with the Table  
doing like you said there is a new error for ds

```auto
object has no attribute 'columnNames'

```

This is the Table

```auto
{
  "$": [
    "ds",
    192,
    1708507081387
  ],
  "$columns": [
    {
      "name": "fut_id",
      "type": "Integer",
      "data": []
    },
    {
      "name": "bin_no",
      "type": "String",
      "data": []
    },
    {
      "name": "plate_no",
      "type": "String",
      "data": []
    },
    {
      "name": "real_cast_no",
      "type": "String",
      "data": []
    },
    {
      "name": "apm_park_name",
      "type": "String",
      "data": []
    },
    {
      "name": "cast_date",
      "type": "String",
      "data": []
    },
    {
      "name": "extraction",
      "type": "String",
      "data": []
    },
    {
      "name": "flask_status",
      "type": "String",
      "data": []
    },
    {
      "name": "delete",
      "type": "String",
      "data": []
    }
  ]
}

```

Can you help me?

---

<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:** [February 21, 2024, 9:22am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/12 "2024-02-21T09:22:17Z")

</div>

huh... I tried with your table, and it works just fine.

Did you copy and paste the script as is, then replaced the line with the query ?  
This script pulled the data from the table, not just the table: check the end of the first line.  
If you didn't do this, then you might be trying to get the column names of the table component, and not of its data.

That's the only thing I can think of.

---

<div class="post-metadata">

**Author:** ![Francesco\_Vittadini](https://avatars.discourse-cdn.com/v4/letter/f/9dc877/32.png) [@Francesco\_Vittadini](https://forum.inductiveautomation.com/u/Francesco_Vittadini)\
**Post date:** [February 21, 2024, 9:24am UTC](https://forum.inductiveautomation.com/t/addrow-to-dataset/86026/13 "2024-02-21T09:24:58Z")

</div>

> [@pascal.fragnoud](#):
>
> `self.parent.getChild("bin_flex").getChild("Table").props.data`

My bad ... my fault ....  
I fixed the links and it's fine  
Thanks a lot again!!!
