Trigger group on DB value change

I know I’ve read about this (a while ago) and I’m sure it’s possible. I don’t have time to read through every post and try different search criteria to find the answer, so I’ll just ask.

Is it possible to trigger a group when a value in the database changes? I can’t seem to figure it out. I think my head is buried too deep in this project and after I walk away for the night I’ll probably remember.

When an operator scans a batch number off their batch paperwork, FactorySQL checks to make sure it’s an approved batch number, and if it was checked as DONE the last time it was shut down. It then sets two bits high or low depending on what it found on the SQL server. If an operator needs to re-process a batch that had been marked as DONE, a supervisor can open an Access database file, find the bath number, and un-check DONE. Upon seeing that change I’d like FactorySQL to write a 0 to that bit (This is a different group than the one that runs when a new batch number is scanned.)

I just can’t make it work right. I’ll think I’ve got it working, then realize it’s not correct. Now I’m so lost it just keeps oscillating that bit high and low every second.

So, when they modify the done bit of any batch in the table you want FactorySQL to do something?

The main problem is that each FactorySQL group is watching a particular row of a table. It seems unlikely that you would have a group for each batch. However, if you’re only interested in the most recent batch (or the most recently scanned), that might work.

In a general way, you can trigger off of a database value by creating a query-based action item set to “run always” (ie ignore trigger) mode, which you can then set to be the group’s trigger. In your case, you can set the group to trigger on 0.

If your value is flipping between 0 and 1, make sure you don’t accidentally have 2 things writing to the address. This can often happen by having an action item write to an opc item, but then also having the group or opc item set to “bi-directional” or “db->opc” mode. If writing from an action item, try setting the opc item to “read only”.

Hope this helps, feel free to post with clarifications if I was way off the mark in interpreting your question!

Regards,

I’ve got a SQL action item named SelectDone “SELECT RunDone FROM tblExistingNumbers where RunNumber = ({RunNumber})”. In this case, {RunNumber} is the currently scanned batch number. I then have a statement action item saying “If isnull({SelectDone}, 0, {SelectDone})”. That writes to the DONE bit.

Having said that, I think I’ve done away with the idea of having it update the done bit on the fly. If an operator scans a number that was marked as done (which is going to be rare and the exception), the supervisor can reset it to not done from their desk, and the operator can click a button I’ve put on the screen “Reset and rescan”. It resets the page to where it would be if it just loaded. Then I use the group already in place for checking the table of existing numbers. It’ll catch the new “done” status of that number then. The number of times they’ll be trying to legitimately restart a run that was previously marked as done will be very small. So I think for now I’ve got my situation figured out.