Modify Transaction Group in Scripting

I have a project with several transaction groups which log data to various tables. Each line in the plant represents a Block Item in the transaction group. When the customer adds new line to the plant, I want to go into the existing transaction group(s) and add a new Item to the block(s) only changing the equipment ID in the new entry. I would like to be able to essentially export the transaction group to an XML file, iterate through it until I find ns=2:s=Retail.AS_001.Common.AIR_P_HA then insert a row and copy that string only changing AS_001 to AS_002. Then I would import the file back into the Bridge and replace the transaction group with the new file.

Well this is a bit of an old post, but you certainly can do that in 7.6. Just right-click on the group and choose Export -> to XML, make your changes, and Import the same way.

That is exactly what we do now. What I am looking to do is automate this process in scripting since some of the transaction groups are long and it becomes tedious to edit them.

You can build a tool to provide that sort of functionality in Ignition.

With system.file.readFileAsString you can read in an XML export of the transaction group; using Python string operations you can add the appropriate entries to the XML file, and finally write them back to another XML file, then manually add that to your project.

This would at least save you the tedious work of manually iterating through the XML document to make the few changes you need. However this will only be useful if what you are adding or changing in the transaction group follows a well defined pattern.

You could also write a script directly with Python to do this. It’s a good exercise if you are trying to learn Python like myself. I recently wrote a script to generate some UDTs for Ignition. Use the XML export file as a template, then add in the functions you need.

This would then give you a starting point to create other XML files as the basic read/write functionally to the files shouldn’t change, just the string formatting of the XML file.

Thanks for all the replies. I have created a script to edit the exported XML file and save a new XML with the additions (or deletions). This works well, but I was hoping to extend it a bit. I have several template transaction groups exported to XML so I can simply call my function to modify them as needed then re-import manually. I also am creating the Database connection in scripting and that works well. Unfortunately, I can’t create an internal Realtime provider in scripting (unless someone knows a secret). At any rate, the whole exercise is really an excuse to get better at Python and because I am lazy and prone to mistakes when doing tedious tasks. So far, I am pleased with the improvements.

I am not sure if you are still looking into this but I did find this function that is now available in 7.8: system.groups.loadFromFile

Thanks, I’m always looking for more elegant ways to do things. I’ll give this one a try when I get a chance.