Adding a transform to Table Data being written from a property change script

Hello everyone!

I am using a property change script to write data to a table. I then need to add a transform to modify the colors of the rows of the table depending on the value inside of them. When Trigger becomes True, it runs a query and moves that data into the table. I did it this way so that I could parameterize the query that it runs.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if previousValue and (previousValue.value != currentValue.value):
		TableData = system.db.runNamedQuery(self.view.params.NamedQueryName)
		self.getSibling("Table").props.data = TableData

Here is the code that works as a transform to change the table row colors:

def transform(self, value, quality, timestamp):
    output_json = []

    style_orange = {"backgroundColor": "#d61a3c"}
    style_green = {"backgroundColor": "#00b050"}
    
    for row in range(value.getRowCount()):
            row_object = {}
            row_value = {}
            row_style = {}
            for col in range(value.getColumnCount()):    
                row_value[value.getColumnName(col)] = value.getValueAt(row, col)
                row_object['value'] = row_value
                
                if value.getColumnName(col) == 'CycleDelta':
                    if value.getValueAt(row, col) < 0:
                        row_style = style_orange
                    elif value.getValueAt(row, col) >= 0:
                        row_style = style_green
    
                row_object['style'] = row_style
                
            output_json.append(row_object)
            
    return output_json

Is there a way for me to add the transform?

Run the second script as part of your first script. Do it all in the one script.

2 Likes

Why do you need a transform? Is the table also updating based on a binding?

Just put the function in a library script, and call it at the end of your script prior to setting the table's data prop.

1 Like

I tried that, the issue is the script uses value.GetColumnCount which throws an error.

Provide value as a function argument to your library function.

1 Like

So at the end of my script I can call the RowColor function and pass value in. Except value isn't something that exists yet in my property change script. How would I define value such that the library script will be able to call value.GetRowCount and value.GetValue

It's TableData.

So, something like this:

self.getSibling("Table").props.data = someScript.myTransform(TableData)

Your transform becomes:

return someScript.myTransform(value)
2 Likes

Create your library script like this:

def setTableRowColors(params):
    value = system.db.runNamedQuery(params)

    #insert your "transform script here"

Then your property change script would become:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    if previousValue and (previousValue.value != currentValue.value):
        self.getSibling("Table").props.data = yourLibrayScriptName.setTableRowColors(self.view.params.NamedQueryName)
3 Likes

Thank you both! Have a good weekend and Happy Memorial Day!