# Update Perspective Table - unicode indices must be integers

**URL:** <https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [May 19, 2022, 6:52pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804 "2022-05-19T18:52:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [May 19, 2022, 6:52pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/1 "2022-05-19T18:52:14Z")

</div>

I’ve gotten stuck on how to make my table in Perspective editable and write back to the database. Here’s the process:

1. Table data bound to query (default format)

2. The following script runs on the query, making all cells except month editable

```auto
# convert dataset to dict where specified columns are editable
	editableCols = ["Budget","Monthly Actuals","Monthly Forecast"]
	ds = value
	colNames = ds.getColumnNames()
	d = []
	for i in range(ds.rowCount):
		rowDict = {}
		for col in colNames:
			editable = False
			if col in editableCols:
				editable = True
			rowDict[col] = {"value":ds.getValueAt(i,col),"editable":editable}
		d.append(rowDict)
	return d

```

This seems to be successful.

1. Use onEditCellCommit to update the database. (I opted to update all the columns to avoid SQL injection, but maybe that’s not necessary?)

```auto
	#update perspective table
	# Get the value that was typed into the cell
	valueToSet = event.value
	self.props.data[event.row][event.column] = valueToSet
	
	#define table values
	month=self.props.data[event['row']]['Month']['value']
	budget=self.props.data[event['row']]['Budget']['value']
	monthlyActuals= self.props.data[event['row']]['Monthly Actuals']['value']
	monthlyForecast=self.props.data[event['row']]['Monthly Forecast']['value']
	
	#update database table
	query='Program Metrics/R and D/UpdateRDDataByLocalId'
	parameters={
		"local_Id":'247',
		"metric_Month":month,
		"budget":budget,
		"monthly_Actuals":monthlyActuals,
		"monthly_Forecast":monthlyForecast
	}
	system.db.runNamedQuery(query, parameters)
	

```

1. The error occurs

Error running action ‘component.onEditCellCommit’ on Embedded\_Program\_Views/R&D@D/root/FlexContainer\_4/FlexContainer\_0/Table: Traceback (most recent call last):  
File “function:runAction”, line 8, in runAction  
TypeError: unicode indices must be integers

I’ve tried using float() to convert the values retrieved from the table to float, but that didn’t improve things. Any suggestions?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 19, 2022, 7:03pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/3 "2022-05-19T19:03:50Z")

</div>

I see `[event.row]` in the fourth line, then `[event['row']]` in the seventh line. IIRC, adding the def at the top would make that line 8

---

<div class="post-metadata">

**Author:** ![gdube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gdube/32/41701_2.png) [@gdube](https://forum.inductiveautomation.com/u/gdube)\
**Post date:** [May 19, 2022, 8:13pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/4 "2022-05-19T20:13:31Z")

</div>

> [@Andrea\_Rector](#):
>
> `self.props.data[event['row']]`

That's funny.  
You'll probably fix it by having `self.props.data[event.row]` instead of what you have.

EDIT: oops, didn't realize Jordan already had the fix.

EDIT2: actually, is it instead your column index that's wrong?  
In props.data, I can't create an object/row with a key with a space in it in the Designer.

EDIT3: no, it works in script. Hm.

---

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [May 19, 2022, 8:25pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/5 "2022-05-19T20:25:36Z")

</div>

Hm I don’t think those are the issues. If i change to event.row and directly write a value for the columns with a space (instead of trying to pull the value from self), I still get the same error. See below for the edited script.

EDIT: If I directly write a value for budget instead of trying to pull the value from self, the script works fine. so the problem is somehow related to pulling the value from self.

```auto
	#update perspective table
	# Get the value that was typed into the cell
	valueToSet = event.value
	self.props.data[event.row][event.column] = valueToSet
	
	#define table values
	month=self.props.data[event.row]['Month']['value']
	budget=self.props.data[event.row]['Budget']['value']
	monthlyActuals= 200 #self.props.data[event.row]['Monthly Actuals']['value']
	monthlyForecast=300 #self.props.data[event.row]['Monthly Forecast']['value']
	
	#update database table
	query='Program Metrics/R and D/UpdateRDDataByLocalId'
	parameters={
		"local_Id":'247',
		"metric_Month":month,
		"budget":budget,
		"monthly_Actuals":monthlyActuals,
		"monthly_Forecast":monthlyForecast
	}
	system.db.runNamedQuery(query, parameters)
	

```

---

<div class="post-metadata">

**Author:** ![gdube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gdube/32/41701_2.png) [@gdube](https://forum.inductiveautomation.com/u/gdube)\
**Post date:** [May 19, 2022, 8:31pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/6 "2022-05-19T20:31:26Z")

</div>

Ah, I just reproduced your issue.

You’re setting the new value directly to your column, effectively replacing your object `{'value': ..., 'editable': ...}`.

So the fix is probably:  
`self.props.data[event.row][event.column]['value'] = valueToSet`

---

<div class="post-metadata">

**Author:** ![gdube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gdube/32/41701_2.png) [@gdube](https://forum.inductiveautomation.com/u/gdube)\
**Post date:** [May 19, 2022, 8:35pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/7 "2022-05-19T20:35:57Z")

</div>

I will add that you don’t have to convert your DataSet to a dictionary if you don’t need cell-specific settings. You can just configure table.props.columns and set which one is editable in there.

---

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [May 20, 2022, 5:10pm UTC](https://forum.inductiveautomation.com/t/update-perspective-table-unicode-indices-must-be-integers/59804/8 "2022-05-20T17:10:25Z")

</div>

Thanks so much for your help! Such a simple solution.

About converting the dataset to a dictionary… From what i understand the editable property doesn’t work quite right for columns in perspective, so you have to use the cell-specific setting unfortunately.
