Forum Discussion

dortego's avatar
dortego
Ideator III
7 years ago
Solved

onBeforeUpdate - 'Not a single item' error

I have onBeforeAdd and onBeforeDelete methods on an ItemType to change a property depending on the status of that property on other instances of that ItemType. Those work fine. But when I tried to ad...
  • christopher_gillis's avatar
    7 years ago

    Hello,

    The issue you're likely running into is that updating the other items in the database is causing an endless loop of onBeforeUpdates. That's why you haven't seen the issue with the onBeforeAdd or onBeforeDelete events.

    One workaround to this would be to specify that you do not want server events to run when you make your updates within the onBeforeUpdate event. You can do this by adding an attribute called serverEvents and setting it to 0. This would look like the code below.

    myItem.setAttribute("serverEvents", "0");
    myItem.apply();

    One note is that you'll need to set this attribute on every item that you're trying to update. We have a blog post on using these standard attributes if you're interested in learning more about them. 

    Chris