Power Table Scripting

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.

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

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

1 Like

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.

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.

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.

2 Likes

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

nothing, just hadn’t done it is all…