# 2nd arg can't be coerced to org.python.core.PySequence\[\] for addRows function

**URL:** <https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547>\
**Category:** Ignition\
**Tags:** ignition79, database, scripting\
**Created:** [September 5, 2018, 3:32pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547 "2018-09-05T15:32:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 5, 2018, 3:32pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/1 "2018-09-05T15:32:00Z")

</div>

Thought this might be a good topic since I couldn’t find it on the forum.

Here’s what I’m trying to do since the notation is a little confusing

1. delete a row/rows from tableT1 (lines 1-5) (this code works)
2. take the deleted row/rows from the tableT1 and add them to the data on tableT2 which is on a different popup window (rest of code)(error)

```auto
table = event.source.parent.getComponent("TableT1")
data = table.data

selected = table.selectedRows

newData = system.dataset.deleteRows(data, selected)
table.data = newData

table2 = system.gui.getWindow("T2T3T1 Popups/T2 Popup").rootContainer.getComponent("TableT2")
data2 = table2.data

newData2 = system.dataset.addRows(data2,selected)
table2.data = newData2

system.gui.getWindow("T2T3T1 Popups/T2 Popup").rootContainer.getComponent("TableT2").data = newData2

```

There are two problems with the second half of the code

1. If I don’t have the pop-up folder expanded in designer it throws TypeError: Window : T2T3T1 Popups/T2 Popup is not open. I can get past this by just opening up the folder.

2: For line 12 or TypeError: addRows(): 2nd arg can’t be coerced to org.python.cogsre.PySequence[]  
I don’t know what coerced means, but the way i understand the addRows function works is addRows(dataset, int (default bottom), PySequence). both tables have same number of columns with the same headers

Much Thanks in advance

---

<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:** [September 5, 2018, 3:42pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/2 "2018-09-05T15:42:05Z")

</div>

AddRows requires a sequence of sequences - a Python list of lists, where each sublist has as many elements as there are columns in the dataset (the types also have to match, but that’s another problem).

If you just need to add a single row, then use `system.dataset.addRow`, not `addRows`; or, pack your values into another sequence:  
`newData2 = system.dataset.addRows(data2, [selected])`  
It’s very unlikely this is going to do what you want/work at all, though - if you’re allowing multi-selection on the source table, then your `selected` variable will have an inconsistent length, which is not compatible with the way you’re passing things into the `addRows` function. If you have a single-column destination dataset, then you could “transpose” the sequence with a list comprehension:  
`newData2 = system.dataset.addRows(data2, [[row] for row in selected])`

That comprehension will take an input long list:  
`[0, 1, 2, 3]`  
and transpose it into a 2-d sequence of single-element lists:

```auto
[
	[0],
	[1],
	[2],
	[3]
]

```

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 5, 2018, 4:09pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/3 "2018-09-05T16:09:16Z")

</div>

> [@paul-griffith](#):
>
> If you just need to add a single row, then use system.dataset.addRow, not addRows; or, pack your values into another sequence:
> 
> newData2 = system.dataset.addRows(data2, [selected])  
> newData2 = system.dataset.addRows(data2, [[row] for row in selected])

I have the table set to select Single Interval. I figured since the deleteRows worked of both single or interval selection addRows would function in a similar fashion.

You were correct that what I'm doing is not compatible with the way I'm passing things into the addRows function. When I inputted your suggesting lines of code it threw a different error on the same line.  
IndexError: Number of values (1) in row 1 doesn't match number of columns (12) in dataset.

---

<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 5, 2018, 4:11pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/4 "2018-09-05T16:11:18Z")

</div>

Your `selected` variable contains the row numbers. For addRows(), you need complete row _contents_. You need to extract them into a 2d list of lists before you delete from the original dataset.

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 5, 2018, 4:20pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/5 "2018-09-05T16:20:37Z")

</div>

> [@pturmel](#):
>
> You need to extract them into a 2d list of lists before you delete from the original dataset.

I'm a little confused isn't [[row] for row in selected] putting it into a 2d list of lists? Do I just need to reorder the code?

---

<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 5, 2018, 4:24pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/6 "2018-09-05T16:24:25Z")

</div>

It’s putting row numbers into a 2d list. You need row contents. Something like this:

```auto
deletedRows = [[data.getValueAt(r, c) for c in range(data.columnCount)] for r in selected]

```

---

<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:** [September 5, 2018, 4:26pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/7 "2018-09-05T16:26:27Z")

</div>

`table.selectedRows` is a list of _row indexes_. Your ultimate goal is to copy a list of _row contents_ into your destination dataset. You will need to create a data structure (a list of lists suitable for addRows is easiest) _at_ the source before trying to paste them into the destination.

@pturmel’s last snippet does what you need - go through each selected row, then copy the contents of _each column_ from the source dataset into a python list (and each of those rows is then put into another list)

The output of that comprehension will be directly able to pass to `system.dataset.addRows()`

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 5, 2018, 4:45pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/8 "2018-09-05T16:45:33Z")

</div>

Ah Awesome I get it!! Can’t possibly thank you guys enough 🙏

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [March 30, 2022, 1:38pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/9 "2022-03-30T13:38:54Z")

</div>

I am trying the same thing but getting error as long object not iterable …

```auto
vTab=self.getSibling("Table1").props.data
	selectedData=self.getSibling("Table1").props.selection.data
	selectedRow=self.getSibling("Table1").props.selection.selectedRow
	downSelectedRow=self.getSibling("Table2").props.selection.selectedRow
	downTable=self.getSibling("Table2").props.data
       deletedRows = [[vTab.getValueAt(r, c) for c in range(vTab.columnCount)] for r in selectedRow]
#	for row in range(len(selectedData)):
		

	newData=system.dataset.addRows(downTable, downSelectedRow+1, deletedRows)

	self.getSibling("Table2").props.data=newData

	vTab = system.dataset.deleteRows(vTab, selectedRow)
	self.getSibling("Table1").props.data=vTab

```

Plz help

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [March 30, 2022, 1:45pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/10 "2022-03-30T13:45:28Z")

</div>

This is my initial code before editing as per the suggestions here…

```auto
	vTab=self.getSibling("Table1").props.data
	selectedData=self.getSibling("Table1").props.selection.data
        selectedRow=self.getSibling("Table1").props.selection.selectedRow
	newRow=[vTab.getValueAt(selectedRow,'Id'),vTab.getValueAt(selectedRow,'Description'),vTab.getValueAt(selectedRow,'IsPrimary')]
	system.perspective.print(selectedData)
	downSelectedRow=self.getSibling("Table2").props.selection.selectedRow
	downTable=self.getSibling("Table2").props.data
	system.perspective.print("downTable"+str(downTable))
	for row in range(len(selectedData)):
		
		newRow=[selectedData[row].SrNo,selectedData[row].Id,selectedData[row].Description,selectedData[row].IsPrimary]
		system.perspective.print(newRow)

		newData=system.dataset.addRow(downTable, downSelectedRow+row, newRow)
		system.perspective.print(" _____________")
		system.perspective.print(newData)

# downSelectedRow=downSelectedRow+1
		system.perspective.print(downSelectedRow)
		self.getSibling("Table2").props.data=newData
		system.perspective.print("newData"+str(newData))
		system.perspective.print("new row added successfully")
		vTab = system.dataset.deleteRow(vTab, selectedRow)
		self.getSibling("Table1").props.data = vTab
		system.perspective.print("row deleted")
	

```

above code deletes multi selected rows but it is adding only one single row …plz help

---

<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:** [March 30, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/11 "2022-03-30T14:16:53Z")

</div>

`selectedRow` is a long.

In the OP, they were using the vision table components `selectedRows` property which returned a list of selected row numbers.

I don’t understand exactly what your are trying to accomplish with this code (other than to delete rows). How are you expecting to determine how many rows need to be deleted?

If you are wanting to take all of the rows from `Table 1` and remove them from `Table 2` that would be done as follows:

```python
deletedRows = [[vTab.getValueAt(r,c) for ci in range(vTab.columnCount)] for r in range(vTab.rowCount)]

```

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [March 30, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/12 "2022-03-30T14:46:58Z")

</div>

> [@lrose](#):
>
> `deletedRows = [[vTab.getValueAt(r,c) for ci in range(vTab.columnCount)] for r in range(vTab.rowCount)`

I want the selected rows to be deleted and deleted rows to be copied in table 2 but my above code deletes deleted rows but only one from that deleted rows(last selected row) is getted added/copied to table 2..plz help

---

<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:** [March 30, 2022, 2:59pm UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/13 "2022-03-30T14:59:58Z")

</div>

I am trying to help, but I am struggling to understand what you are after.

Are you saying that the user selects a number of rows from Table 1, and then performs some action, maybe clicks a button, and then those selected rows should be removed from Table 1 and added to Table 2?

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [March 31, 2022, 5:59am UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/14 "2022-03-31T05:59:39Z")

</div>

yes right…the below-shared code deletes selected rows in table 1 but from that selected rows only one row gets added to table 2 but I want all the selected rows to be added in table 2 …consider if I selected 3 rows from table 1 then after clicking on the button it deletes all that selected 3 rows but from that deleted rows only one row gets added to table 2

```auto
vTab=self.getSibling("Table1").props.data
	selectedData=self.getSibling("Table1").props.selection.data
        selectedRow=self.getSibling("Table1").props.selection.selectedRow
	newRow=[vTab.getValueAt(selectedRow,'Id'),vTab.getValueAt(selectedRow,'Description'),vTab.getValueAt(selectedRow,'IsPrimary')]
	system.perspective.print(selectedData)
	downSelectedRow=self.getSibling("Table2").props.selection.selectedRow
	downTable=self.getSibling("Table2").props.data
	system.perspective.print("downTable"+str(downTable))
	for row in range(len(selectedData)):
		
		newRow=[selectedData[row].SrNo,selectedData[row].Id,selectedData[row].Description,selectedData[row].IsPrimary]
		system.perspective.print(newRow)

		newData=system.dataset.addRow(downTable, downSelectedRow+row, newRow)
		system.perspective.print(" _____________")
		system.perspective.print(newData)

# downSelectedRow=downSelectedRow+1
		system.perspective.print(downSelectedRow)
		self.getSibling("Table2").props.data=newData
		system.perspective.print("newData"+str(newData))
		system.perspective.print("new row added successfully")
		vTab = system.dataset.deleteRow(vTab, selectedRow)
		self.getSibling("Table1").props.data = vTab
		system.perspective.print("row deleted")

```

---

<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:** [March 31, 2022, 11:59am UTC](https://forum.inductiveautomation.com/t/2nd-arg-cant-be-coerced-to-org-python-core-pysequence-for-addrows-function/19547/15 "2022-03-31T11:59:03Z")

</div>

Assuming that you have the tables bound to a dataset, the following will work:

```python
vTab = self.getSibling("Table1").props.data
selectedData = self.getSibling("Table1").props.selection.data
downTable = self.getSibling("Table2").props.data

dataToRemove = [[row[col] for col in row.keys()] for row in selectedData]
self.getSibling("Table1").props.data = system.dataset.deleteRows(vTab,dataToRemove)
self.getSibling("Table2").props.data = system.dataset.addRows(downTable,dataToRemove)

```
