[00:00]
As we've seen in previous lessons, transaction groups make it easy to work with data from our tag structure or from our device directly and store or sync that data against a database table. In this lesson, we'll discuss an additional possibility for a transaction group item, which is the expression item. Expression items allow us to populate a group item from custom calculations inside our transaction group using ignitions expression language. In many ways, expression items are like expression tags except that expression items exist purely within the transaction group and can reference other group items directly. These items can be helpful when the transaction group requires internal calculations to decide when to run, what to store, or what to return. For example, maybe we have some complex triggering requirements, say our group should only run on Thursdays when a certain device is online and a specific tag value is above 100. We could configure an expression item that represents whether these conditions are true, and then use it as a trigger for our group.
[01:04]
We discussed triggers in other lessons. Here we'll be looking at a slightly different application of expression items. I have in my designer here a historical transaction group that's simply configured to log three sign values to separate columns in a table. What I'd like to do is add a fourth data column that computes the sum of these three values. We'll begin by adding our new expression item. You might've noticed that in our interface here, there are two separate boxes for expression items: run always and triggered. And we'll discuss the difference between these two boxes in a later lesson. For now, I'm just going to find the plus tag icon at the top of the interface, click the little drop down on the right, and select New expression item. I could also have right clicked on a specific box to add it directly. Once inside our configuration interface, I'm just going to give my new item a name of sum and then a data type of float. And at the bottom of this interface, there's a right target section. By default, we're not using this new item in any way, but if I set the target type to database field and then set the target name to sum, we'll actually log this new data point to the database.
[02:13]
And with that, we're ready to configure our expression. So in the menu on the left, I'm going to go to Expression/SQL, and then I'll select an expression type of expression, is also SQL query type which we'll discuss in a later lesson. Now that I'm in my expression editor, I can use the tag icon on the right hand side to add references to tags or to group items, which are in this group tags tab. So one at a time here, I'll select one of my OPC items, click "Okay" to add it and then type + and go back into my tag interface, select the next one, hit "Okay", type +, and then go back in one final time and hit "Okay". And with that, we'll have our expression all sorted out. So we're simply summing together all three other fields and we'll be logging it into a column called sum.
[03:08]
So I'll click okay here to finish up. And now, of course, we need to save our group to see it in action. So if I click "Save" here, we should see a lashed value coming through on my item that matches this sum of the other three. And then if I go into Tools at the top here and pull up my database query browser, I can open up that table we're working with and we'll see that our sum is coming through just fine. Expression items offer us opportunities to customize the logic behind how a transaction group works beyond simple data references, and they can serve a meaningful purpose in many different flavors of transaction group.