Skip to Content

A while ago I wrote a very short ABSL script which works very well and many people do not know why.

The goal for it was a duplicate check on a node. Imagine you have a BO with an Accounts node. Now you add Accounts to this node, but would like to prevent an Account to be added twice.

Put this into the AfterModify of the node:

// Check double accounts in list

foreach(var entry in this.ToRoot.Accounts) {

       if(entry.ID == this.ID && this != entry) {

             raise MyMessage.Create(“E”, “Account can only be added once.”);

       }

}

The interesting part is the if statement in the loop where it checks if there is already an entry with the same as the current ID. However, the new node entry is already in the buffer and therefore in the list. How do you know if you found the current one (which is ok) or a duplicate one (which is not ok)?


The magic is here: “this != entry” which compares the node IDs of the currently created entry with the node IDs in the loop. If these are different, you found the duplicate.


So keep in mind that “this” is also just a UUID which can sometimes become handy for usecases like this.


Best Regards,

Stefan

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply