# Inserting rows via python script in a table

**URL:** <https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 29, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490 "2022-07-29T20:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 29, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/1 "2022-07-29T20:12:11Z")

</div>

I have a table that I need to add rows into:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/5/15a603742e7c7d4af9c443619ba90a06fd41a861.png)

here is the transform I currently have on it where I am appending a column on to the table:

```auto
	table = self.getSibling("Table_0").props.data
	accounted_badge_num = [B['Badge_Num'] for B in table]
	json_obj = []
	for V in value:
		py_dic = {"value":dict(V)}
		if py_dic["value"]['BadgeNum'] in accounted_badge_num:
			py_dic["value"]['isAccountedFor'] = True
			py_dic["style"]={"backgroundColor":"green"}
		else:
			py_dic["value"]['isAccountedFor'] = False
		json_obj.append(py_dic)

			
	return json_obj

```

How do I append rows?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 29, 2022, 8:13pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/2 "2022-07-29T20:13:41Z")

</div>

OR is the answer to just use and INSERT INTO on the named query of this table?

---

<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:** [July 29, 2022, 8:16pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/3 "2022-07-29T20:16:27Z")

</div>

What is initiating the row add operation? Is there any data validation?

Probably, the answer is to INSERT the row in the database using whatever method, and then refreshing the binding on the table.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 29, 2022, 8:32pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/4 "2022-07-29T20:32:47Z")

</div>

Here is the query from the named query:

```auto
SELECT 
	  VP.PERSONNUM AS 'BadgeNum'
	, FORMAT( VP.INPUNCHDTM, 'hh:mm') AS 'ClockINTime'
	, VP.PERSONFULLNAME AS 'Name'
	, HOMELABORLEVELNM5 AS 'Shift'
	, HOMELABORLEVELNM6 AS 'Dept'
	, HOMELABORLEVELDSC7 AS 'JobTitle'
	, HOMELABORLEVELDSC4 AS 'Supervisor'
FROM 
	VP_EMPCUREARNTIME AS VP 
	LEFT OUTER JOIN VP_EMPLOYEEV42 ON VP.PERSONNUM = VP_EMPLOYEEV42.PERSONNUM 
	LEFT OUTER JOIN TIMEZONE ON VP_EMPLOYEEV42.TIMEZONENAME = TIMEZONE.ENGLISH
WHERE 
	(VP.LABORLEVELNAME3 = '0065')
	AND VP.INPUNCHDTM is not Null
	AND VP.LABORLEVELNAME5 NOT IN ('9', 'S')
	AND (VP.STARTDTM > DATEADD(d, - 1, GETDATE()))
	AND (VP.GMTSTARTDTM <= DATEADD(S, - TIMEZONE.GMTOFFSET, GETDATE()))
	AND (VP.GMTENDDTM IS NULL OR VP.GMTENDDTM >= DATEADD(S, - TIMEZONE.GMTOFFSET, GETDATE()))
order by HOMELABORLEVELNM6, HOMELABORLEVELDSC7

```

When I try and INSERt it tells me that I cant due to effecting other data sources

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 29, 2022, 8:49pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/5 "2022-07-29T20:49:12Z")

</div>

I was just informed that I cannot mod the database that table was created form, I have READ access only.

Any ideas on how I can add rows via the current transform I am using?

```auto
        table = self.getSibling("Table_0").props.data
	accounted_badge_num = [B['Badge_Num'] for B in table]
	json_obj = []
	for V in value:
		py_dic = {"value":dict(V)}
		if py_dic["value"]['BadgeNum'] in accounted_badge_num:
			py_dic["value"]['isAccountedFor'] = True
			py_dic["style"]={"backgroundColor":"green"}
		else:
			py_dic["value"]['isAccountedFor'] = False
		json_obj.append(py_dic)

			
	return json_obj

```

---

<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:** [July 29, 2022, 10:42pm UTC](https://forum.inductiveautomation.com/t/inserting-rows-via-python-script-in-a-table/62490/6 "2022-07-29T22:42:24Z")

</div>

Well if this is being pulled from a database, then updating just the table in perspective will not do you much good.

As soon as the binding is refreshed for any reason, any changes that have been made will be lost unless you somehow update the database table.

Note that ignition doesn’t run under your credentials but under those that the ignition service is using. So that user needs to have read and write access to the database.
