addRow to Dataset

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:

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

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

2 Likes

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.

1 Like

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

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

1 Like

thanks it works perfectly ... such a small modification ... :smile:

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

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

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

[{"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

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:

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.

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

object has no attribute 'columnNames'

This is the Table

{
  "$": [
    "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?

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.

2 Likes

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

1 Like