# Power Table Scripting

**URL:** <https://forum.inductiveautomation.com/t/power-table-scripting/19348>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [August 21, 2018, 5:34pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348 "2018-08-21T17:34:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bprice](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bprice/32/83520_2.png) [@bprice](https://forum.inductiveautomation.com/u/bprice)\
**Post date:** [August 21, 2018, 5:34pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/1 "2018-08-21T17:34:50Z")

</div>

I’m trying to turn specified cells in a power table to red. I have created custom properties to the Root Container. I am pulling values from a Database Query, successfully. I am trying to read those values and use the script below to turn the cells that are out of spec red. I’m not real sure why it isn’t working.

This script is on the configureCell function for the power table.

```auto
	kibbleUCL = self.parent.kibbleUCL
	kibbleLCL = self.parent.kibbleLCL
	netWeightUCL = self.parent.netWeightUCL
	netWeightLCL = self.parent.netWeightLCL
	prodTempUCL = self.parent.prodTempUCL
	prodTempLCL = self.parent.prodTempLCL
	ambientTempUCL = self.parent.ambientTempUCL
	ambientTempLCL = self.parent.ambientTempLCL
	diffTempUCL = self.parent.diffTempUCL
	diffTempLCL = self.parent.diffTempLCL
	densityUCL = self.parent.densityUCL
	densityLCL = self.parent.densityLCL

#Visual Inspection
	if colName == 'Visual Inspection (Check = Ok / No Check = Not Ok)':
		if value == 0:
			return {'background' : 'red'}

#Kibble/Bit Ratio
	if colName == 'Kibble / Bit Ratio':
		if value > kibbleUCL:
			return {'background' : 'red'}
		elif value < kibbleLCL:
			return {'background' : 'red'}

#Correct Packaging
	if colName == 'Correct Packaging (Check = Ok / No Check = Not Ok)':
		if value == 0:
			return {'background' : 'red'}

#Bag Defects
	if colName == 'Bag Defects (Check = Ok / No Check = Not Ok)':
		if value == 0:
			return {'background' : 'red'}
	
#Net Weight
	if colName == 'Net Weight':
		if value > netWeightUCL:
			return {'background' : 'red'}
		elif value < netWeightLCL:
			return {'background' : 'red'}

#Prod Temp
	if colName == 'Product Temp':
		if value > prodTempUCL:
			return {'background' : 'red'}
		elif value < prodTempLCL:
			return {'background' : 'red'}
			
#Ambient Temp
	if colName == 'Ambient Temp':
		if value > ambientTempUCL:
			return {'background' : 'red'}
		elif value < ambientTempLCL:
			return {'background' : 'red'}

#Ambient Temp
	if colName == 'Difference in Temps':
		if value > diffTempUCL:
			return {'background' : 'red'}
		elif value < diffTempLCL:
			return {'background' : 'red'}	
	
#Density Setpoint
	if colName == 'Density':
		if value > densityUCL:
			return {'background' : 'red'}
		elif value < densityLCL:
			return {'background' : 'red'}

#Rework
	if colName == 'Rework (Check = Yes / No Check = No)':
		if value == 1:
			return {'background' : 'red'}
		
#Date Code Correct
	if colName == 'Date Code is Correct (Check = 5/5 bags / No Check = 1 or more / 5)':
		if value == 0:
			return {'background' : 'red'}

#Bags Sealed
	if colName == 'Bag sealed Properly (Check = 5/5 bags / No Check = 1 or more / 5)':
		if value == 0:
			return {'background' : 'red'}

#Date Code Legible
	if colName == 'Date Code is Legible (Check = 5/5 bags / No Check = 1 or more / 5)':
		if value == 0:
			return {'background' : 'red'}

#Date Code Correct Location
	if colName == 'Date Code is Correct Location (Check = 5/5 bags / No Check = 1 or more / 5)':
		if value == 0:
			return {'background' : 'red'}

```

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [August 21, 2018, 5:56pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/2 "2018-08-21T17:56:35Z")

</div>

It looks good, are you sure those column names are correct? Maybe try column index instead to verify?

---

<div class="post-metadata">

**Author:** ![bprice](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bprice/32/83520_2.png) [@bprice](https://forum.inductiveautomation.com/u/bprice)\
**Post date:** [August 21, 2018, 7:38pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/3 "2018-08-21T19:38:40Z")

</div>

The column names are correct. If I take the self.parent out and put a constant number in place of the definitions, the cells will work. But I’m wanting to pull the values from the database query.

---

<div class="post-metadata">

**Author:** ![ctonge](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@ctonge](https://forum.inductiveautomation.com/u/ctonge)\
**Post date:** [August 21, 2018, 7:49pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/4 "2018-08-21T19:49:37Z")

</div>

I’ve never tried to reference the parent container using self.parent. You sure that works? Seems like it could be the issue if you replace those references and it executes…

Update: it does work…just tested. So I’m not sure what it could be, unless you have a typo in your root container custom property names?? or one is missing? I’m just grasping at straws now…hopefully someone can help you.

---

<div class="post-metadata">

**Author:** ![bprice](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bprice/32/83520_2.png) [@bprice](https://forum.inductiveautomation.com/u/bprice)\
**Post date:** [August 21, 2018, 8:29pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/5 "2018-08-21T20:29:49Z")

</div>

So basically I had to compare it by calling out the data type.

For instance:

```
if colName == 'Net Weight':
	if value > float(netWeightUCL):
		return {'background' : 'red'}
	elif value < float(netWeightLCL):
		return {'background' : 'red'}

```

Thanks for responding and for taking a stab at it.

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [August 21, 2018, 9:47pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/6 "2018-08-21T21:47:43Z")

</div>

Out of curiosity, what do you use instead of self.parent?

---

<div class="post-metadata">

**Author:** ![ctonge](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@ctonge](https://forum.inductiveautomation.com/u/ctonge)\
**Post date:** [August 21, 2018, 11:25pm UTC](https://forum.inductiveautomation.com/t/power-table-scripting/19348/8 "2018-08-21T23:25:31Z")

</div>

nothing, just hadn’t done it is all…
