Passing Tag Value to Named Query Parameter

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 :stuck_out_tongue:

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?

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?

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.

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.

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.

Does this also occur on the button press?

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

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

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

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.

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).

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