title: Updating custom field is ending into infinite loop
body: <p>I have a custom field in AR Invoice and Memos (Screen ID AR301000) for the corresponding AP Ref. Nbr. And in the similar manager another custom field in AP Bills and Adjustment (Screen ID AP301000) for the corresponding AR Ref. Nbr. </p>
  
  <p>I am trying to update AP Ref. Nbr. on AR screen when user updates the AR Ref. Nbr. in AP screen. </p>
  
  <p>For example-</p>
  
  <p>I am on AR Screen Invoice 0001, I am updating AP Ref. Nbr. to abc01. System will automatically update the AP Bill abc01 with the corresponding AR Ref. Nbr. with 0001.</p>
  
  <p>I have below code written to achieve this but it runs into infinite loop as both it is trying to update the corresponding fields in other screen. Let me know if I missing anything or there is a better way.</p>
  
  <p>On AR Graph Extension</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class ARInvoiceEntryExtension : PXGraphExtension&lt;ARInvoiceEntry&gt;
  {
   protected virtual void ARInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
   {
    var row = (ARInvoice)e.Row;
    if (row != null &amp;&amp; sender.IsDirty)
    {
     ARRegisterExtension ext = PXCache&lt;ARRegister&gt;.GetExtension&lt;ARRegisterExtension&gt;(row);
  
     if (ext != null &amp;&amp; !string.IsNullOrEmpty(ext.UsrAPRefNbr))
     {
      APInvoiceEntry graph = PXGraph.CreateInstance&lt;APInvoiceEntry&gt;();
  
      APInvoice apRow = PXSelect&lt;APInvoice,
       Where&lt;APInvoice.refNbr, Equal&lt;Required&lt;APInvoice.refNbr&gt;&gt;&gt;&gt;.Select(graph, ext.UsrAPRefNbr);
  
      if (apRow != null)
      {
       APRegisterExtension ext1 = PXCache&lt;APRegister&gt;.GetExtension&lt;APRegisterExtension&gt;(apRow);
       if (ext1 != null &amp;&amp; string.IsNullOrEmpty(ext1.UsrARRefNbr))        //Update only if it is empty
       {
        ext1.UsrARRefNbr = row.RefNbr;
  
        graph.Document.Current = apRow;
  
        graph.Caches[typeof(APRegister)].SetValue&lt;APRegisterExtension.usrARRefNbr&gt;(apRow, row.RefNbr);
        graph.Caches[typeof(APRegister)].Update(apRow);
        graph.Actions.PressSave();
       }
      }
     }
    }
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>On AP Graph Extension</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class APInvoiceEntryExtension : PXGraphExtension&lt;APInvoiceEntry&gt;
  {
   protected virtual void APInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
   {
    var row = (APInvoice)e.Row;
    if (row != null &amp;&amp; sender.IsDirty)
    {
     APRegisterExtension ext = PXCache&lt;APRegister&gt;.GetExtension&lt;APRegisterExtension&gt;(row);
  
     if (ext != null &amp;&amp; !string.IsNullOrEmpty(ext.UsrARRefNbr))
     {
      ARInvoiceEntry graph = PXGraph.CreateInstance&lt;ARInvoiceEntry&gt;();
  
      ARInvoice arRow = PXSelect&lt;ARInvoice,
       Where&lt;ARInvoice.refNbr, Equal&lt;Required&lt;ARInvoice.refNbr&gt;&gt;&gt;&gt;.Select(graph, ext.UsrARRefNbr);
  
      if (arRow != null)
      {
       ARRegisterExtension ext1 = PXCache&lt;ARRegister&gt;.GetExtension&lt;ARRegisterExtension&gt;(arRow);
       if (ext1 != null &amp;&amp; string.IsNullOrEmpty(ext1.UsrAPRefNbr))        //Update only if it is empty
       {
        ext1.UsrAPRefNbr = row.RefNbr;
  
        graph.Document.Current = arRow;
  
        graph.Caches[typeof(ARRegister)].SetValue&lt;ARRegisterExtension.usrAPRefNbr&gt;(arRow, row.RefNbr);
        graph.Caches[typeof(ARRegister)].Update(arRow);
        graph.Actions.PressSave();
       }
      }
     }
    }
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>AR Cache Extension</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class ARRegisterExtension : PXCacheExtension&lt;ARRegister&gt;
  {
   public abstract class usrAPRefNbr : PX.Data.IBqlField
   {
   }
  
   protected string _usrAPRefNbr;
  
   [PXDBString(15)]
   [PXUIField(DisplayName = "AP Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]
  
   [APInvoiceType.RefNbr(typeof(Search3&lt;PX.Objects.AP.Standalone.APRegisterAlias.refNbr,
   InnerJoinSingleTable&lt;APInvoice, On&lt;APInvoice.docType, Equal&lt;PX.Objects.AP.Standalone.APRegisterAlias.docType&gt;,
    And&lt;APInvoice.refNbr, Equal&lt;PX.Objects.AP.Standalone.APRegisterAlias.refNbr&gt;&gt;&gt;,
   InnerJoinSingleTable&lt;Vendor, On&lt;PX.Objects.AP.Standalone.APRegisterAlias.vendorID, Equal&lt;Vendor.bAccountID&gt;&gt;&gt;&gt;,
   OrderBy&lt;Desc&lt;APRegister.refNbr&gt;&gt;&gt;))]
   public virtual string UsrAPRefNbr
   {
    get; set;
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>AP Cache Extension</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class APRegisterExtension : PXCacheExtension&lt;APRegister&gt;
  {
   public abstract class usrARRefNbr : PX.Data.IBqlField
   {
   }
  
   protected string _usrARRefNbr;
  
   [PXDBString(15)]
   [PXUIField(DisplayName = "AR Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]
  
   [ARInvoiceType.RefNbr(typeof(Search3&lt;PX.Objects.AR.Standalone.ARRegisterAlias.refNbr,
   InnerJoinSingleTable&lt;ARInvoice, On&lt;ARInvoice.docType, Equal&lt;PX.Objects.AR.Standalone.ARRegisterAlias.docType&gt;,
    And&lt;ARInvoice.refNbr, Equal&lt;PX.Objects.AR.Standalone.ARRegisterAlias.refNbr&gt;&gt;&gt;,
   InnerJoinSingleTable&lt;Customer, On&lt;PX.Objects.AR.Standalone.ARRegisterAlias.customerID, Equal&lt;Customer.bAccountID&gt;&gt;&gt;&gt;,
   OrderBy&lt;Desc&lt;ARRegister.refNbr&gt;&gt;&gt;))]
   public virtual string UsrARRefNbr
   {
    get; set;
   }
  }</code></pre>
  </div>
  </div>
  </p>