Performing conditional statement within transaction group

I have been configuring my first transaction group. The datatable has been created and is working good. I have multiple machines wich have two asynchronous counters. I monitor the primary counter for a zero to initiate a new row and insert the accumulated value of the second counter. I then have a second group configured to monitor the first counter for acc = preset and update the “actual” count and then grab the accumulated value from the second counter again (I also set a flag for row complete so that I don’t write over this field again). What I would like to do is to be able to log the change in the second counter and have the number be a variable linked to the primary count “basically it is the number of defects in a lot”. But if the secondary counter has rolled over, or if my initial value is greater than the current, I would like to add the two and then subtract the first for my actual. I am not sure if what I need to do is a stored procedure, or if I can add a case clause to the where condition in the action tab of the group configuration. F_REJECT_INIT is my first capture of the reject count.
I would like to on trigger:
if count_reject > F_REJECT_INIT;
F_REJECT = count_reject - F_REJECT_INIT
else F_REJECT = count_reject_preset - F_REJECT_INIT + count_reject. I would need to add the count_reject OPC tag I just realized.
Any help would be greatly appreaciated. Let me know if this isn’t quite clear. Thanks.

Yes, that is possible. You have to create triggered expression items that perform those calculations. You might have a couple expression items.

The expression items make use of the full expression language and can reference any item in that group. They can also write the value of the expression to another tag or to the database. Expression items run in sequential order from top to bottom. So any expression item can reference values from previous expression items.

Also, expression items that are run-always can be used as a trigger. Run-always expression items ignore the trigger and run at the update rate of the group. Triggered expression items only run when the trigger is set and active.

Thanks for the reply. So in my example/screenshot, my trigger is the stop_box expression item which is continuously updated. So when this trigger executes, then starting from top to bottom:

  1. count_actual is updated to the DB record (via a where condition)
  2. count_reject is written to the DB record (via a where condition)
  3. room is updated to the DB record

So what I should do is:

  1. change the OPC tag count_reject to read-only.
  2. create a new expression tag called reject_init which is evaluated through a query like
    (SELECT F_REJECT_INT FROM DB WHERE KEY =60) (this will have to be above the room expression tag.)
  3. And then with a new triggered expression item with a target type set to my F_REJECT field evaluate the if instruction like

Thanks in advance

Right. That way you can calculate what you want to go into the database and the PLC.

I have created a script module that executes on the start count condition. Basically the trigger is monitoring the PLC register for a zero. However, due to conditions with the equipment or with alarms the count will get reset. So what I wrote is a small script that looks at the DB and counts records that have started but never completed and deletes all except the latest entry. I have tested this script, however when I run with the group, the script appears to execute before the insert of the actual new record. Always leaving me with two non completed records. I am calling the script via the runScript() command in the expression tag and the tag is the last in line as far as top to bottom positioning. I tired to:
import time
But it looks as if the actual update to the DB does not occur until this script completes the execute.
I would prefer to not have this run continuously. I noticed there are now DB functions in the expression tag. Would this work better? I just liked having the logic in one place since I have multiple machines.

Thanks in advance

The expression items evaluate before the group completes. It would be better to use the DB functions in that case.