AnsweredAssumed Answered

How can I rollback a tag creation using AFSDK?

Question asked by SvenBatalla on Jul 6, 2015
Latest reply on Jul 6, 2015 by SvenBatalla

We currently have an application that allows users to create new elements in PIAF.  Naturally, this is done using the AFSDK.  During the process, if an exception occurs, the element can be rolled back by simply undoing the checkout.  However, if tags were created in PI during the process (and this is still done using the AFSDK), the tags themselves are not removed.  So the question is:  how can I "undo" the tag creation?


Here is some sample code to show what we're talking about (shortened for brevity and clarity):


   // Create the new element
   AFElement element = new AFElement("My Element", db.ElementTemplates["My Template"]);

   // Create the needed PI tag attribute
   element.Attributes["My Attribute"].DataReferencePlugin = AFDataReference.GetPIPointDataReference(pisystem);
   element.Attributes["My Attribute"].DataReference.ConfigString = "...";
   element.Attributes["My Attribute"].DataReference.CreateConfig();

   // Commit the work
   // - At this point, all is well.  The element is created and the tag is created too.
catch(Exception ex)
   // An error has occurred, so undo the element creation and let the error bubble up to the next layer
   // - At this point, the element rollback occurs, but the tag remains in existence


There is obviously code that we could write to maintain the list of tags we've created up to that point and then manually delete them within the catch, but this seems like extra effort that I shouldn't need to do.  If I have to, that's fine, but with the element rollback possible, I hoped something similar would exist for PI.  Can anyone help with this?