# Referencing a field entry within named query

**URL:** <https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453>\
**Category:** Ignition\
**Created:** [March 22, 2022, 1:36pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453 "2022-03-22T13:36:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 1:36pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/1 "2022-03-22T13:36:34Z")

</div>

I am trying to use a numeric field to specify which employee to add an hour to using a button,  
but i am stuck as my best attempt (picture below) was unsuccessful.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/2/02b2c137be324e6dabf4af8082d15ae7074764ed.png)

Any advice or alternate methods would be appreciated

---

<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:** [March 22, 2022, 1:41pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/2 "2022-03-22T13:41:09Z")

</div>

A named query isn’t a view component so it doesn’t have a self property.

Try  
`WHERE employeeid = :employeeid`

See [Named Queries - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Named+Queries#NamedQueries-Binding).

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 1:47pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/3 "2022-03-22T13:47:38Z")

</div>

You can’t. Not like this. A named query can’t reference elements from your UI.

You need to do it the other way around: call that name query on your button’s events, where you can reference something like a numeri entry field.

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 1:52pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/4 "2022-03-22T13:52:44Z")

</div>

I have done that and it works but only when i specify in the query that employeeid = 1208 (or any valid ID)  
My problem is wanting the numeric field entry to be the thing to specify what employeeid to select  
this is my script event for a button  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/699aa2f170b5f6c76ffd0163d555099a4a16e26e.png)

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 1:54pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/5 "2022-03-22T13:54:03Z")

</div>

This works but where and how do i specify what employeeid is

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 1:56pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/6 "2022-03-22T13:56:51Z")

</div>

You need to pass the parameter to the named query:

```python
employee_id = self.getSibling("NumericEntryField").props.value
params = {
    'employeeid': employee_id 
}
system.db.runNamedQuery('query_name', params)

```

---

<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:** [March 22, 2022, 1:59pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/7 "2022-03-22T13:59:06Z")

</div>

Tip: Please post code using the `</>` code formatting button. That way we can copy and edit it into our answers. If you only post a picture then we have to type it all out.

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 1:59pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/8 "2022-03-22T13:59:54Z")

</div>

Ok thank you for your help

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 2:14pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/9 "2022-03-22T14:14:34Z")

</div>

I tried inserting this into my query and got the errors below,  
I thought the query’s couldn’t reference the UI elements?  
Should i make a separate query to define these parameters and link that to the components?

```auto
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 3, in runAction
java.lang.Exception: java.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employee_id'.

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 3, in runAction
java.lang.Exception: java.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employee_id'.

	caused by Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employee_id'.
	caused by SQLServerException: Incorrect syntax near 'employee_id'.

Ignition v8.1.15 (b2022030114)
Java: Azul Systems, Inc. 11.0.14.1

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/10 "2022-03-22T14:16:20Z")

</div>

Put the code in the button’s `onActionPerformed` event, not in the query.

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 2:27pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/11 "2022-03-22T14:27:20Z")

</div>

Hey sorry to keep asking but this is what i put on the button

```auto
employee_id = self.getSibling("NumericEntryField_0").props.value
	params = {
	'employeeid': employee_id 
	}
	system.db.runNamedQuery('test', params)

```

But i get syntax errorslike these

```auto
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 7, in runAction
java.lang.Exception: java.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employeeid'.

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 7, in runAction
java.lang.Exception: java.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employeeid'.

	caused by Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'employeeid'.
	caused by SQLServerException: Incorrect syntax near 'employeeid'.

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/12 "2022-03-22T14:30:51Z")

</div>

The error is in the query. Show us what it looks like now.

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 2:32pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/13 "2022-03-22T14:32:44Z")

</div>

```auto
update hoursworked
set hours = hours + 1   
where employeeid = :employeeid 

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 2:42pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/14 "2022-03-22T14:42:23Z")

</div>

Make sure the type your pass to the namedQuery matches the one it’s supposed to receive.

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

The numeric entry field’s `value` property is a long.

Apart from that, I don’t know.

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [March 22, 2022, 2:49pm UTC](https://forum.inductiveautomation.com/t/referencing-a-field-entry-within-named-query/57453/15 "2022-03-22T14:49:15Z")

</div>

It worked! I changed it to int4 and removed a binding I had on my numeric entry and it works exactly as i wanted now!  
Thank you for your time Pascal I really appreciate it, you are a real hero.
