how can i run query after my tag will active?
i am trying to run a query once my tag active. i make it run by using toggle button
( if event.stateChange == event.SELECTED:
system.db.runUpdateQuery("INSERT INTO demo.line_4_data (line, date, days, starttime, endtime, reason)" + " VALUES ('%s', '%s', '%s', '%s', '%s', '%s')" %(p, curday, x, startTime, endTime, reason), getKey=1)
)
it is working when window is open but if i open another window its not working.
is it because i put that query in component? can component script run only if component window is open?
if yes thn how i can make it dynamic so that query can run always based on tag active?
Add a value change script to the tag configuration. It sounds like the script lives on a component on a window/view, so that's why it is only executing when the window/view is open.
Do you want the query to run once on the leading edge, poll at some rate? Is this query dependent on any client provided information? If multiple clients are open to the same window should they insert different data?
You window and your using event in your code, so that make me think this is Vision, is that the case?
As a side note, it's recommended to use system.db.runPrepUpdate() especially if you are accepting any user enter information as a parameter.
Also, please post code using the preformatted text option </>.
I see you're grabbing some dates off the UI. You'll need to connect those to tags and use system.tag.readBlocking() to get those values into your script.
You almost certainly should be getting an error because "event" is not defined.
i dont know this came 45 min before now , but i triggerd tag so many time afrer to check but error isnot coming, and value changed scrip also not working
It will suppress duplicate errors to avoid clogging up the log. That's your error. You'll need to rework your script to run in the gateway scope with the tags on the UI page in question.
i created named Query and put in value changed and it worked. i dint know why it was not running through system.db.runUpdatequery or with updatePrep but works with name query
runUpdateQuery() and runPrepUpdate() need a db connection name if it's running from the gateway scope.
I've gotten into the habit of always specifying the db connection for both consistency and robustness.