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

**URL:** <https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [May 24, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889 "2024-05-24T17:07:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 24, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/1 "2024-05-24T17:07:43Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f96b44c85fb669521ea4ae2e8b24b79cb55c801b.png)

```python
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:

```python
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?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 24, 2024, 5:09pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/2 "2024-05-24T17:09:57Z")

</div>

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

---

<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:** [May 24, 2024, 5:10pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/3 "2024-05-24T17:10:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 24, 2024, 5:11pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/4 "2024-05-24T17:11:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 24, 2024, 5:12pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/5 "2024-05-24T17:12:56Z")

</div>

Provide `value` as a function argument to your library function.

---

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 24, 2024, 5:20pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/6 "2024-05-24T17:20:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 24, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/7 "2024-05-24T17:21:41Z")

</div>

It's `TableData`.

So, something like this:

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

```

Your transform becomes:

```python
return someScript.myTransform(value)

```

---

<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:** [May 24, 2024, 5:22pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/8 "2024-05-24T17:22:48Z")

</div>

> [@Luke\_Smith1](#):
>
> value.GetColumnCount

Create your library script like this:

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

    #insert your "transform script here"

```

Then your property change script would become:

```python
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)

```

---

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 24, 2024, 5:32pm UTC](https://forum.inductiveautomation.com/t/adding-a-transform-to-table-data-being-written-from-a-property-change-script/90889/9 "2024-05-24T17:32:55Z")

</div>

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