Dictionaries as arguments in runScript expression

Hi,

I am trying to make dynamic priorities for an alarm by querying the priorities from a database.
I use the runScript function in the expression to call the system.db.runNamedQuery. However, how do I pass in the arguments for system.db.runNamedQuery when the argument should be a dictionary?

Here is my expression so far but that is giving an error:

Is there a neat trick to accomplish this?

I am aware that I could use another function like system.db.runQuery with the query as a string. But I want to keep all the queries as Named Queries so I can maintain all of them from there.

Dictionary literal syntax like you’re attempting to use is Python, not part of the expression language, so yo won’t be able to do it inline like that.

Probably for the best because you’re attempting to build yourself into a performance nightmare using runScript like that.

That said… you could pass the argument as a JSON string and call your own project function that turns the JSON into a dictionary and then calls runQuery with that dictionary…

2 Likes

Hi Kevin,

I see. Thank you for the suggestion.

So performance wise, what would be the better option if I want the user to be able to change the priority for an alarm? I am not a big fan of creating multiple memory tags, one for each alarm in my UDT in order to do that. That was the reason I went for this option where I solve it via the database. What is the performance problems with doing it in the database and calling the priority with the runScript function?

Is this in Vision? If so, you really don’t want to use runScript for anything that needs to make round trips to the gateway. Alarm status, DB queries, tag or opc calls, or anything else. runScript() uses the foreground thread and will freeze your GUI on any network hesitation. Run a client over a WAN and it’s likely to crash.

2 Likes

I see. Thanks for pointing that out !

Been there, done that. I avoid runScript like the plague nowadays

As noted in that other thread, I love runScript/objectScript. Just limited to local data.