Update an item causes recursive loop

Hi team,

So I am looking to run a method on an item whenever it is updated to update two hidden properties on the item that drive some functionality later on down the workflow.

The issue I am having is that when I use the onAfterUpdate event, because the method updates the item it causes a recursive loop and runs itself indefinitely.

I attempted onAfterVersion however this caused two weird scenarios - the logging wouldn't show the correct result until the second time the item was saved and even then it never actually updated the properties. I have this same event running onAfterAdd and it works successfully there but I need it to update anytime the item is saved.

Finally, I got the idea to run it via a wrapper from a client event on the form. In this case, onFormPopulate causes the recursive loop again, and so I am attempting a field even for onChange of the field that drives these in question. It still seems to have an issue so any suggestions would be welcome.

Parents Reply
  • Strange, I was sure that serverEvents would do the trick. It´s often combined with setAttribute("doGetItem","0"); , but it should not make a difference.

    So you basically have an ItemType like e.g. "Part". After clicking save your Method will edit something in the same item. Correct?

    onFormPopulates will trigger the loop if you refresh the Form in your Method.

    I have to admit, when ever I update something after regular edit, I don´t use AML but SQL. This is also what Aras does a lot. This way you prevent unnecessary history entries.



Children
  • Maybe I am doing something wrong with the serverEvents attribute?

    That is correct. I am editing the same item that is saved.

    Oddly, my wrapper method doesn't refresh the form but it still loops :/

    I didn't want to use sql because I wanted the history to show when this value gets updated (Its the product category for our changes)

    Here is the portion of the code in question, the server events is commented out due to me changing over to the onAfterVersion in my original testing since it didnt work:

        ecrItem.setAction("update");
        
        WriteLog("ECR in Edit Mode - Item Lock Status = "+ecrItem.getLockStatus()+" Item ID "+ecrItem.getID());
        // ecrItem.setAttribute("serverEvents", "0");
        ecrItem.setAttribute("version", "0");
        ecrItem.setProperty("a_gpr_by_prodcat", setRegions);
        ecrItem.setProperty("a_design_center", setRegions);
        if (ecrItem.getProperty("a_eco_status") == null)
            {
                ecrItem.setProperty("a_eco_status", "Stage 1 of 11 - ECR Created");
            }
        ecrItem = ecrItem.apply();

  • I used this code in ItemType 'Manufacturer' as onAfterUpdate Method and it updated the 'name' property without server crash:

    this.setAction("edit");
    this.setAttribute("serverEvents","0");
    this.setProperty("name","myupdatedname");
    Item result = this.apply();

    return result;

    Maybe some other Method influence your current one. Maybe LifeCylce Method? Or do you automatic revision mode?

  • It's possible. I did end up getting everything working. 

    I ended up creating a client wrapper as a method triggered from a form event onFormPopulate. The client method validates that the item is locked then calls the server method to perform the update. It's working as expected now.