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
  • 0 オフライン in reply to AngelaIp

    Thanks for this Angela. The system does definitely collapse :) I don't know that this will work for my case.  In the example here, once the property is set the method will not fire again. In my use case, I need the method to fire and update the property everytime the item is saved. If I use this method, it will apply the first time but then not in any subsequent attempts I believe.

Children
  • Have you tried the attribute serverEvent = 0 in your query? 

    Edit: --> myCall.setAttribute("serverEvents","0");

  • 0 オフライン in reply to AngelaIp

    Yep, that was one of the first things I tried with onAfterUpdate to stop it calling the method recursively but it didn't seem to work.

    Funny enough, when using onAfterVersion I was able to use setAttribute("version","0"); and was able to stop it which is why I switched over to that trigger but it caused other issues as I noted.

  • 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.



  • 0 オフライン in reply to AngelaIp

    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?

  • +1 オフライン in reply to AngelaIp

    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.