Forum Discussion

Morgan's avatar
Morgan
Ideator I
3 years ago
Solved

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.

  • Morgan's avatar
    Morgan
    3 years ago

    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.

10 Replies

    • Morgan's avatar
      Morgan
      Ideator I

      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.

      • AngelaIp's avatar
        AngelaIp
        Ideator I

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

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

  • Why not to use OnBeforeUpdate? In this case you don't need an additional update. Just change the properties of "this".

    [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:bb64e62d-ec92-47d7-8790-c28b886f1e86:type=csharp&text=this.setProperty%28%22a_gpr_by_prodcat%22%2C%20setRegions%29%3B%0D%0Athis.setProperty%28%22a_design_center%22%2C%20setRegions%29%3B%0D%0Aif%20%28this.getProperty%28%22a_eco_status%22%29%20%3D%3D%20null%29%0D%0A%7B%0D%0A%20%20%20%20this.setProperty%28%22a_eco_status%22%2C%20%22Stage%201%20of%2011%20-%20ECR%20Created%22%29%3B%0D%0A%7D%0D%0Areturn%20this%3B]

    • Morgan's avatar
      Morgan
      Ideator I

      Thanks for the suggestion, I never considered that. I'll run a test on this in the future but I've got it working another way.