# Named query returns null for all columns, but only if run in a script

**URL:** <https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 9, 2024, 6:49pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996 "2024-01-09T18:49:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [January 9, 2024, 6:49pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/1 "2024-01-09T18:49:18Z")

</div>

I have a named query that returns values for all columns in the query editor. If I try to run the named query in a script using system.db.runNamedQuery, it returns no rows. There are no parameters and it was working earlier today.

Is this a known bug?

```auto
select UPPER([user_id]) as racfId, 
		prsn_id, 
		last_nm as last_name, 
		frst_nm as first_name, 
		mid_init_txt as middle_initial, 
		up_case_emp_num as employee_num, 
		title_txt as title, 
		addr_txt as addr_line1, 
		ofce_txt as office_loc, 
		city_txt as addr_city, 
		st_txt as addr_state, 
		zip_cd_txt as addr_zip, 
		cntry_nm as addr_country, 
		phn_num as phone_num, 
		mobile_phn_num as cell_phone_num, 
		email_txt as email, 
		substring(unit_key_cd,1,2) as unit, 
		chrg_dept_cd as department, 
		mgr_user_id as manager 
from edl_current.people_and_org_prsninfoutf8_prsn_info_utf8

```

---

<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:** [January 9, 2024, 6:58pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/2 "2024-01-09T18:58:03Z")

</div>

> [@Andrea\_Rector](#):
>
> in a script using system.db.runNamedQuery

In what scope are you running the script? The arguments to `system.db.runNamedQuery()` vary by scope.

(I assume it works in the named query editor's testing tab.)

---

<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:** [January 9, 2024, 7:29pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/3 "2024-01-09T19:29:17Z")

</div>

Do you happen to have a named query in a folder with the exact same name as a named query at the root? Strange things can occur in that case, because of a recently fixed bug.

---

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [January 19, 2024, 9:49pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/4 "2024-01-19T21:49:38Z")

</div>

It looks like it was the scope noted in the script. Thanks. Strange because it worked at one point and hadn't been changed as far as I could tell.

---

<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:** [January 19, 2024, 11:16pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/5 "2024-01-19T23:16:57Z")

</div>

> [@Andrea\_Rector](#):
>
> scope noted in the script

I have no idea what you mean by this. Scripts do not have a scope. Scripts **run** in a scope, based on what calls them.

---

<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:** [January 20, 2024, 2:10pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/6 "2024-01-20T14:10:29Z")

</div>

Is there a place where I can find more info about that ?

---

<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:** [January 20, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/7 "2024-01-20T16:11:24Z")

</div>

There's not much more info than that. Remarkably, it seems to date back to 8.0.0. It's fixed in the latest nightlies and 8.1.37, I think?

It would only manifest in the specific scenario described - a queury in a folder with the same name (the last path attribute) as a query at the root.

---

<div class="post-metadata">

**Author:** ![Andrea\_Rector](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Andrea\_Rector](https://forum.inductiveautomation.com/u/Andrea_Rector)\
**Post date:** [January 22, 2024, 10:48pm UTC](https://forum.inductiveautomation.com/t/named-query-returns-null-for-all-columns-but-only-if-run-in-a-script/83996/8 "2024-01-22T22:48:50Z")

</div>

Sorry, I mean the parameters noted in the script. The named query had no parameters so the original script was:

```auto
userDataset = system.dataset.toPyDataSet(system.db.runNamedQuery(getUsersQuery, {}))

```

I had to remove the empty parameter dictionary to get it to run. Not sure why.
