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 add an onBeforeUpdate method to detect when another property was changed, the 'Not a single item' error shows up. I'm also not able to use the apply() method on any item that is changed on the update method. I just need to know how to make a change to the item stick when using an Update server method.
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