# Passing Tag Value to Named Query Parameter

**URL:** <https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 30, 2024, 4:36pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963 "2024-01-30T16:36:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![NP209](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/np209/32/80704_2.png) [@NP209](https://forum.inductiveautomation.com/u/NP209)\
**Post date:** [January 30, 2024, 4:36pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/1 "2024-01-30T16:36:23Z")

</div>

Hello, I have a Named Query Parameter that I'm trying to update dynamically. Through some research I have read that I cannot call this information directly from a tag and have to pass it in through a Parameter.

I have created a Parameter in my Named Query called :INF but the issue I'm having is updating that value.

I can't find an example script to understand how to update that Parameter. For the moment all I want to do is update that Paramater with a tag value on button press. Both the Tag Value and Parameter are set to STRING.

Can anyone link me a post that has done something like this so I can force feed my brain this information lol or be kind enough to show me 😛

---

<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:** [January 30, 2024, 4:45pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/2 "2024-01-30T16:45:19Z")

</div>

> [@NP209](#):
>
> I can't find an example script to understand how to update that Parameter

Well, you don't "update" a parameter _in_ the named query, you call it with a new value.

You can do that a couple of ways, depending on where/how the named query is being called. Is this configured in a binding?

---

<div class="post-metadata">

**Author:** ![NP209](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/np209/32/80704_2.png) [@NP209](https://forum.inductiveautomation.com/u/NP209)\
**Post date:** [January 30, 2024, 4:51pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/3 "2024-01-30T16:51:18Z")

</div>

What I have right now is a Named Query and a Tag Value I want passed. I was playing around with trying to update it on button press but it sounds like that's not the right way to go about it.

So it sounds like I need to run the query via script and define my parameter there to return a value and have it write to something?

---

<div class="post-metadata">

**Author:** ![elijah.roberts](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@elijah.roberts](https://forum.inductiveautomation.com/u/elijah.roberts)\
**Post date:** [January 30, 2024, 4:52pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/4 "2024-01-30T16:52:20Z")

</div>

Assuming you are binding on a custom prop or equivalent

tagValue = value #Value to pass in to named query...

params = {"INF":tagValue} #Asssign your tag value to the query parameter

system.db.runNamedQuery("yourQueryPath", params) #Run the named query and do something with the result

This is a simple script based of a tag binding, depending on what and where exactly you are trying to run this it could change a bit. you may have to run a tag read and assign that result to the parameter. Hopefully this helps a bit.

---

<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:** [January 30, 2024, 4:55pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/5 "2024-01-30T16:55:28Z")

</div>

> [@NP209](#):
>
> I was playing around with trying to update it on button press but it sounds like that's not the right way to go about it.

No, but how and where you are calling the named query from the approach may change. For instance, lets say you want the results to be shown in a table. You could create a custom property to bind the tag to. Then use a query binding on the table, with the parameter bound to the custom property. On the button click all you would need to do is refresh the binding on the table.

Depending on your needs there are several ways to accomplish the rather generic "use a tag value as a parameter". Just trying to get more information so I can provide an appropriate response.

---

<div class="post-metadata">

**Author:** ![NP209](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/np209/32/80704_2.png) [@NP209](https://forum.inductiveautomation.com/u/NP209)\
**Post date:** [January 30, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/6 "2024-01-30T16:56:58Z")

</div>

I have a SQL Table that I'm trying to filter using a Tag value to get one specific value. I want to later send these values out in a summary email.

---

<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:** [January 30, 2024, 4:58pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/7 "2024-01-30T16:58:13Z")

</div>

> [@NP209](#):
>
> I want to later send these values out in a summary email.

Does this also occur on the button press?

---

<div class="post-metadata">

**Author:** ![NP209](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/np209/32/80704_2.png) [@NP209](https://forum.inductiveautomation.com/u/NP209)\
**Post date:** [January 30, 2024, 4:59pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/8 "2024-01-30T16:59:07Z")

</div>

Yes, but later It will likely be tied to something else.

---

<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:** [January 30, 2024, 5:02pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/9 "2024-01-30T17:02:52Z")

</div>

> [@elijah.roberts](#):
>
> params = {":INF": tagValue}

Elijah, I think that should be **INF** , not **:INF**. You can fix your post using the pencil icon edit link below it.

See also, [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831)

---

<div class="post-metadata">

**Author:** ![elijah.roberts](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@elijah.roberts](https://forum.inductiveautomation.com/u/elijah.roberts)\
**Post date:** [January 30, 2024, 5:04pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/10 "2024-01-30T17:04:20Z")

</div>

Yeah now that you mention it I realize that param is shown in the query not his actual param name. Thanks

---

<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:** [January 30, 2024, 5:04pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/11 "2024-01-30T17:04:39Z")

</div>

So what I think you need is, a script that can be executed based upon some user action (such as a button press)

I that case you would need to do these basic things:

- Read the tag value
- Call the Query
- Generate the report
- Send the report.

To send a value to a named query you just include a key value pair in the parameters dictionary.

```auto
system.db.runNamedQuery('YourNamedQuery', {'INF':tagValue})

```

Depending on the context of the call, you may need to include the project name. the Key in the params dictionary should match the parameter name, without the colon, exactly (case sensitive).

---

<div class="post-metadata">

**Author:** ![NP209](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/np209/32/80704_2.png) [@NP209](https://forum.inductiveautomation.com/u/NP209)\
**Post date:** [January 30, 2024, 5:06pm UTC](https://forum.inductiveautomation.com/t/passing-tag-value-to-named-query-parameter/84963/12 "2024-01-30T17:06:28Z")

</div>

Okay I will try this out and play around with it some. Thanks for the help!
