# Configured Event onActionPerformed Script Run NamedQuery

**URL:** <https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 24, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675 "2024-07-24T14:52:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Edwards1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremy_edwards1/32/71714_2.png) [@Jeremy\_Edwards1](https://forum.inductiveautomation.com/u/Jeremy_Edwards1)\
**Post date:** [July 24, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/1 "2024-07-24T14:52:01Z")

</div>

## I am configuring an event script onActionPerformed of a Button that takes data that is input into Text Fields and Dropdown selections. When the button is pressed, it performs a system.db.runNamedQuery(path, params). The Named Query works perfect in the Testing function, however, the button script is not working. Below is the script. Any help figuring out what I am doing wrong would be greatly appreciated.

```python
def runAction(self, event):
	dbConnection = "FRW_IGNITION_HIST"
	chillerID = self.parent.custom.ChillerID
	chillerName = self.getSibling("ChillerName").props.text
	wo = self.getSibling("WorkOrder").props.value
	fromTank = self.getSibling("StartTank").props.value
	toTank = self.getSibling("EndTank").props.value
	extraTank1 = self.getSibling("EndTank1").props.value
	extraTank2 = self.getSibling("EndTank2").props.value
	lot = self.getSibling("LotNumber").props.text
	feedtype = self.getSibling("FeedType").props.text
	prodtempmin = self.getSibling("ProdTempMin").props.value
	prodtempmax = self.getSibling("ProdTempMin").props.value
	jobtype = self.getSibling("JobType").props.value
	status = self.getSibling("Status").props.value
	statusreason = self.getSibling("StatusReason").props.value
	comment = self.getSibling("Comments").props.text
	timestamp = self.getSibling("LogDate").props.text
	dt = self.getSibling("MonthYear").props.text
	tagPath = "Chillers_%s/Chiller_%s/WOLoaded"%(plantName,chillerName)
	user = self.session.props.auth.user.userName

	path = 'Refrigeration/ChillerWOEntry'
	params = {'chillerID':ChillerID, 'chillerName':ChillerName,	'wo':WorkOrderNum, 'fromTank':StartTank, 'toTank':EndTank, 'extraTank1':EndTank1, 'extraTank2':EndTank2, 'lot':LotNumber, 'feedtype':FeedType, 'prodtempmin':ProdTempMin, 'prodtempmax':ProdTempMax, 'jobtype':JobType, 'status':Status, 'statusreason':StatusReason, 'comment':Comments, 'timestamp':LogDate, 'dt':DT, 'user':OperatorName}		
	system.db.runNamedQuery(str(path, params))

```

* * *

Thank you,  
Jeremy

---

<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:** [July 24, 2024, 2:55pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/2 "2024-07-24T14:55:56Z")

</div>

Please edit your post (pencil icon), select all of the **code** , then click the "preformatted text" button ( **\</\>** ).

---

<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:** [July 24, 2024, 2:58pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/4 "2024-07-24T14:58:01Z")

</div>

> [@Jeremy\_Edwards1](#):
>
> `system.db.runNamedQuery(str(path, params))`

What's the `str()` function there for?

Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Post code - not pictures of code.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Edwards1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremy_edwards1/32/71714_2.png) [@Jeremy\_Edwards1](https://forum.inductiveautomation.com/u/Jeremy_Edwards1)\
**Post date:** [July 24, 2024, 2:58pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/5 "2024-07-24T14:58:57Z")

</div>

The (str()) was my latest attempt to make it work. I initially tried it without the (str\*

---

<div class="post-metadata">

**Author:** ![Kevin\_Flener](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@Kevin\_Flener](https://forum.inductiveautomation.com/u/Kevin_Flener)\
**Post date:** [July 24, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/6 "2024-07-24T15:26:38Z")

</div>

Just a shot in the dark based on the little information given and the fact that I am rather new to all of this myself.

I think maybe you have reversed the order of your data and your named query's parameters. As an example, if the parameter defined in the named query is **ChillerID** and you want to used the value defined in the script **chillerID** , it should be

```python

params = {'ChillerID' : chillerID,...}

```

---

<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 24, 2024, 3:31pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/7 "2024-07-24T15:31:37Z")

</div>

> [@Kevin\_Flener](#):
>
> Just a shot in the dark

You must have dark vision.

@Jeremy_Edwards1  
The keys in the params dictionary must match with case sensitivity, the parameters that are used in the Authoring tab of the Named Query. Any parameter which doesn't match is ignored.

Also of note, youve created a variable to hold the database, but you are not providing that in your params dictionary. If you have set the named query to have a parameter provided database, then you must also include that in your prameters dictionary.

Change that, and remove the `str()` and you should get an expected result.

You could avoid all of this, if you used a custom property with a Named Query Binding, and then just refreshed the binding with the button. Will be more performant as well.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Edwards1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremy_edwards1/32/71714_2.png) [@Jeremy\_Edwards1](https://forum.inductiveautomation.com/u/Jeremy_Edwards1)\
**Post date:** [July 24, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/8 "2024-07-24T15:45:47Z")

</div>

@lrose ,  
Thank you, I will go back through it and make any case corrections. I have already removed the (str().  
Just for clarification: the {'key' :value} is like this correct?

```python
`chillerName = self.getSibling("ChillerName").props.text`
'chillerName':ChillerName

```

key = chillerName  
value = ChillerName

Here is the Named Query

```python
INSERT INTO CH_Log( ChillerID, Comments, DT, EndTank, EndTank1, EndTank2, FeedType, JobType, LogDate, LotNumber, OperatorName, ProdTempMax, ProdTempMin, StartTank, Status, StatusReason, WorkOrderNum)
VALUES( :ChillerID, :Comments, :DT, :EndTank, :EndTank1, :EndTank2, :FeedType, :JobType, :LogDate, :LotNumber, :OperatorName, :ProdTempMax, :ProdTempMin, :StartTank, :Status, :StatusReason, :WorkOrderNum)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 24, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/9 "2024-07-24T15:58:59Z")

</div>

Consider also refactoring your code like this, to dramatically reduce duplication (and opportunities for typos to slip in):

```python
def runAction(self, event):
    path = 'Refrigeration/ChillerWOEntry'
    params = {
        "chillerID": self.parent.custom.ChillerID,
        "chillerName": self.getSibling("ChillerName").props.text,
        "wo": self.getSibling("WorkOrder").props.value,
        "fromTank": self.getSibling("StartTank").props.value,
        "toTank": self.getSibling("EndTank").props.value,
        "extraTank1": self.getSibling("EndTank1").props.value,
        "extraTank2": self.getSibling("EndTank2").props.value,
        "lot": self.getSibling("LotNumber").props.text,
        "feedtype": self.getSibling("FeedType").props.text,
        "prodtempmin": self.getSibling("ProdTempMin").props.value,
        "prodtempmax": self.getSibling("ProdTempMin").props.value,
        "jobtype": self.getSibling("JobType").props.value,
        "status": self.getSibling("Status").props.value,
        "statusreason": self.getSibling("StatusReason").props.value,
        "comment": self.getSibling("Comments").props.text,
        "timestamp": self.getSibling("LogDate").props.text,
        "dt": self.getSibling("MonthYear").props.text,
        "user": self.session.props.auth.user.userName
    }
        
    system.db.runNamedQuery(path, params)

```

Consider also reading though this thread, especially this post in particular:

> [@Do's and Don'ts when developing First Project with Ignition?](https://forum.inductiveautomation.com/t/dos-and-donts-when-developing-first-project-with-ignition/93592/5):
>
> Bind UI input values to custom properties of the view, and reference those instead of the input value itself. It not only makes for cleaner code without a bunch of getChild/getSibling nonsense with hardwired component names, but ensures that you can reorganize and rename components without breaking those references. Name your UI components/containers. It may seem like unnecessary effort in the short term, but in the long term it will save lots of hassle when trying to navigate your way down t…

---

<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 24, 2024, 4:03pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/10 "2024-07-24T16:03:40Z")

</div>

Do as @paul-griffith showed, do note however, that you do need to match case and name.

So for instance, it should be:

`"ChillerID"` not `"chillerId"`

Also, you have used a "chillerName" parameter, but the query you have showed does not include that parameter.

@paul-griffith probably did not take the time to check the validity of the parameters but rather was just trying to illustrate how to write the code in a best practice form.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 24, 2024, 4:08pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/11 "2024-07-24T16:08:53Z")

</div>

Yeah, good catch. I just had Copilot translate the snippet, didn't look at it in any depth.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Edwards1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremy_edwards1/32/71714_2.png) [@Jeremy\_Edwards1](https://forum.inductiveautomation.com/u/Jeremy_Edwards1)\
**Post date:** [July 24, 2024, 4:15pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/12 "2024-07-24T16:15:30Z")

</div>

Indentation error

---

<div class="post-metadata">

**Author:** ![Jeremy\_Edwards1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremy_edwards1/32/71714_2.png) [@Jeremy\_Edwards1](https://forum.inductiveautomation.com/u/Jeremy_Edwards1)\
**Post date:** [July 24, 2024, 4:18pm UTC](https://forum.inductiveautomation.com/t/configured-event-onactionperformed-script-run-namedquery/93675/13 "2024-07-24T16:18:14Z")

</div>

Sorry, meant to say, Corrected Indentation Error. 🙂
