<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Update an item causes recursive loop</title><link>https://www.aras.com/community/f/development/37642/update-an-item-causes-recursive-loop</link><description>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</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8866?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 14:49:53 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b3bff73d-b8a1-4137-bb66-183840f13afb</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;It&amp;#39;s possible. I did end up getting everything working.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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&amp;#39;s working as expected now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8865?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 14:47:35 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:343ea54c-1056-40c8-92d5-5054fc124ea9</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Thanks for the suggestion, I never considered that. I&amp;#39;ll run a test on this in the future but I&amp;#39;ve got it working another way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8863?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 11:40:01 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:21cf00d7-abc1-4db4-b113-ec2788633e56</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;Why not to use OnBeforeUpdate? In this case you don&amp;#39;t need an additional update. Just change the properties of &amp;quot;this&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;this.setProperty(&amp;quot;a_gpr_by_prodcat&amp;quot;, setRegions);
this.setProperty(&amp;quot;a_design_center&amp;quot;, setRegions);
if (this.getProperty(&amp;quot;a_eco_status&amp;quot;) == null)
{
    this.setProperty(&amp;quot;a_eco_status&amp;quot;, &amp;quot;Stage 1 of 11 - ECR Created&amp;quot;);
}
return this;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8862?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 10:45:13 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:acfc42c1-ab03-40ef-8405-6e52301f9a36</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;I used this code in ItemType &amp;#39;Manufacturer&amp;#39; as onAfterUpdate Method and it updated the &amp;#39;name&amp;#39; property without server crash:&lt;/p&gt;
&lt;p&gt;this.setAction(&amp;quot;edit&amp;quot;);&lt;br /&gt;this.setAttribute(&amp;quot;serverEvents&amp;quot;,&amp;quot;0&amp;quot;);&lt;br /&gt;this.setProperty(&amp;quot;name&amp;quot;,&amp;quot;myupdatedname&amp;quot;);&lt;br /&gt;Item result = this.apply();&lt;/p&gt;
&lt;p&gt;return result;&lt;/p&gt;
&lt;p&gt;Maybe some other Method influence your current one. Maybe LifeCylce Method? Or do you automatic revision mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8854?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 17:04:16 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:034b82c9-eca4-4d2f-929d-86f8a7882272</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Maybe I am doing something wrong with the serverEvents attribute?&lt;/p&gt;
&lt;p&gt;That is correct. I am editing the same item that is saved.&lt;/p&gt;
&lt;p&gt;Oddly, my wrapper method doesn&amp;#39;t refresh the form but it still loops :/&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t want to use sql because I wanted the history to show when this value gets updated (Its the product category for our changes)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    ecrItem.setAction(&amp;quot;update&amp;quot;);
    
    WriteLog(&amp;quot;ECR in Edit Mode - Item Lock Status = &amp;quot;+ecrItem.getLockStatus()+&amp;quot; Item ID &amp;quot;+ecrItem.getID());
    // ecrItem.setAttribute(&amp;quot;serverEvents&amp;quot;, &amp;quot;0&amp;quot;);
    ecrItem.setAttribute(&amp;quot;version&amp;quot;, &amp;quot;0&amp;quot;);
    ecrItem.setProperty(&amp;quot;a_gpr_by_prodcat&amp;quot;, setRegions);
    ecrItem.setProperty(&amp;quot;a_design_center&amp;quot;, setRegions);
    if (ecrItem.getProperty(&amp;quot;a_eco_status&amp;quot;) == null)
        {
            ecrItem.setProperty(&amp;quot;a_eco_status&amp;quot;, &amp;quot;Stage 1 of 11 - ECR Created&amp;quot;);
        }
    ecrItem = ecrItem.apply();&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8853?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 16:52:02 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:27349a51-bb34-4060-aed2-41abdc127e50</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;Strange, I was sure that serverEvents would do the trick. It&amp;acute;s often combined with setAttribute(&amp;quot;doGetItem&amp;quot;,&amp;quot;0&amp;quot;); , but it should not make a difference.&lt;/p&gt;
&lt;p&gt;So you basically have an ItemType like e.g. &amp;quot;Part&amp;quot;. After clicking save your Method will edit something in the same item. Correct?&lt;/p&gt;
&lt;p&gt;onFormPopulates will trigger the loop if you refresh the Form in your Method.&lt;/p&gt;
&lt;p&gt;I have to admit, when ever I update something after regular edit, I don&amp;acute;t use AML but SQL. This is also what Aras does a lot. This way you prevent unnecessary history entries.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8852?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 16:31:22 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:a031d366-0ae5-45fc-b44a-5e2b420acfc6</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Yep, that was one of the first things I tried with onAfterUpdate to stop it calling the method recursively but it didn&amp;#39;t seem to work.&lt;/p&gt;
&lt;p&gt;Funny enough, when using onAfterVersion I was able to use setAttribute(&amp;quot;version&amp;quot;,&amp;quot;0&amp;quot;); and was able to stop it which is why I switched over to that trigger but it caused other issues as I noted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8850?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 16:19:05 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:c701fb68-e4ca-4d99-953c-d09f1de39fc1</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;Have you tried the attribute serverEvent = 0 in your query?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit: --&amp;gt; myCall.setAttribute(&amp;quot;serverEvents&amp;quot;,&amp;quot;0&amp;quot;);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8849?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 16:15:02 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:88ce8992-a754-4a6f-b57a-5b1c9402a375</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Thanks for this Angela. The system does definitely collapse :) I don&amp;#39;t know that this will work for my case.&amp;nbsp; 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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update an item causes recursive loop</title><link>https://www.aras.com/community/thread/8848?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 16:07:51 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:6646f101-fa59-4e12-9228-8ab45444f1ae</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;Cool! What is the practical effect of the loop? Will the system collapse?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Recursive loops can be prevented with fake properities:&amp;nbsp;&lt;/span&gt;&lt;a href="/b/english/posts/tech-tip-utilizing-fake-properties"&gt;https://community.aras.com/b/english/posts/tech-tip-utilizing-fake-properties&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>