# system.db.runNamedQuery \[tx\] syntax

**URL:** <https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390>\
**Category:** Ignition\
**Created:** [February 14, 2021, 1:51pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390 "2021-02-14T13:51:31Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [February 14, 2021, 1:51pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/1 "2021-02-14T13:51:31Z")

</div>

The syntax is documented as  
**system.db.runNamedQuery(project, path, parameters, [tx], [getKey])**

I want to set [getkey] to 1 so I can get the id of the inserted row and feed it back to my table data.

When I run without a [tx] parameter as in

```auto
newRowId = system.db.runNamedQuery('queryInsertRow', {}, , 1) # getKey = 1

```

I get an error:

```auto
SyntaxError: ("mismatched input ',' expecting RPAREN", 
('<function:runAction>', 9, 58, "\tnewRowId = 
system.db.runNamedQuery('queryInsertRow', {}, , 1) # getKey = 1\t \n"))

```

I’ve tried _Null_, _()_, _{}_.

Any ideas?

---

<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:** [February 14, 2021, 2:11pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/2 "2021-02-14T14:11:42Z")

</div>

You can’t leave empty elements in a list of function arguments. Supply `getKey` as a keyword argument if you want to skip the transaction ID.

---

<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:** [February 14, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/3 "2021-02-14T16:08:14Z")

</div>

Thanks, Phil.

```auto
	params = {}
	newRowId = system.db.runNamedQuery('queryInsertRow', params, getKey=1)	 

```

generates an error

```auto
ProjectNotFoundException: project not found: queryInsertRow

```

_queryInsertRow_ is a named query in the project and it operates correctly in named query testing.  
Why is the runNamedQuery looking for the project name?

---

<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:** [February 14, 2021, 6:26pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/4 "2021-02-14T18:26:22Z")

</div>

You must be running it in the gateway. The named query api was misdesigned to not default to its own project when in project scope in the gateway. And the order of parameters established at that time prevents fixing it. ):

All of the other system.db functions take a datasource argument that is optional in any project context, including gateway project contexts.

---

<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:** [February 14, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/5 "2021-02-14T18:44:06Z")

</div>

Thanks, Phil.

1. So how would I determine where it’s running? There’s no clue in the Query Editor.
2. If I have to provide the project name can I get that as a project variable so my code is portable?

Adding in the project name parameter seems to allow runNamedQuery to run.

1. What is the datatype of my variable _newRowId_? (I want to inspect it.)

---

<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:** [February 14, 2021, 7:28pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/6 "2021-02-14T19:28:17Z")

</div>

1. Well, it isn't convenient:

> [@Getting the context in which a function is running?](http://forum.inductiveautomation.com/t/getting-the-context-in-which-a-function-is-running/33977/3):
>
> However you check for scope, consider doing it at the top level of an inherited script module, setting booleans like isDesigner and isGateway. Then just check the booleans everywhere else. Something like this: try: isDesigner = bool(system.util.getSystemFlags() & system.util.DESIGNER\_FLAG) isGateway = False except AttributeError: isDesigner = False isGateway = True

1. [system.project.getProjectName()](https://docs.inductiveautomation.com/display/DOC81/system.project.getProjectName)

2. Depends on your JDBC driver and primary key column type(s).

---

<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:** [February 14, 2021, 8:29pm UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/7 "2021-02-14T20:29:05Z")

</div>

Thank you again for your friendly and excellent assistance.

**system.project.getProjectName()** does exactly that.

I’m using the MySQL JDBC driver and **type(newRowId)** showed me that it’s just an **int**.

I’ve learned quite a bit with your assistance and it’s coming together in my head. I’m actually teaching this stuff in work! “_In the valley of the blind the one-eyed man is king_.”

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [June 22, 2024, 3:30am UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/8 "2024-06-22T03:30:29Z")

</div>

Has this been fixed? I am getting the same error. Named query works fine in designer test but when I call it with getKey=1 it asks for the project.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [June 22, 2024, 3:47am UTC](https://forum.inductiveautomation.com/t/system-db-runnamedquery-tx-syntax/43390/9 "2024-06-22T03:47:31Z")

</div>

I figured it out, once i gave everything a prefix it worked. Mixing getKey=1 without adding path=, parameters=, etc...

makes sense thanks!
