Skip to main content
Solved

Event Trigger FieldUpdate: Copy Invoice Note to Sales Orders

  • October 18, 2022
  • 4 replies
  • 192 views

Forum|alt.badge.img

Hi,

I want to copy field Invoice Note in Invoices to Sales Orders and whenever this field is updated in Invoices, the field in Sales Orders should be updated with same value.

What happen in my mind: create a custom field in Sales Orders, then implement Event Handler FieldUpdated of the field “Invoice Note” set value for custom field.

However, I don’t if it is possible and how to set value for custom field in Sales Order in Event Handler.

Any suggestions greatly appreciated.

Best answer by Leonardo Justiniano

Hi @mrthanhkhoi 

You can try copying the note when you save the invoice:

 

// Extension of SOInvoiceEntry
// Example copying Description

protected void _(Events.RowPersisting<ARInvoice> e)
{
   var query = new SelectFrom<SOOrder>
      InnerJoin<SOInvoice>.On<SOInvoice.sOorderType.IsEqual<SOOrder.oderType>.
      And<SOInvoice.sOOrderNbr.IsEqual<SOOrder.orderNbr>>>
      Where<Use<SOInvoice.refNbr>.AsString.IsEqual<@P.AsString>>.
      View(Base);

   SOOrder so = query.Select(e.Row.RefNbr).TopFirst;

   so.OrderDesc = e.Row.DocDesc;

   Base.Caches[typeof(SOOrder)].Update(so);
   if(Base.Caches[typeof(SOOrder)].Updated.Cast<SOOrder>().Count() > 0)
   {
      Base.Caches[typeof(SOOrder)].Persist(PXDBOperation.Update);                    
   }   
}

 

View original
Did this topic help you find an answer to your question?

4 replies

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi @mrthanhkhoi 

You can try copying the note when you save the invoice:

 

// Extension of SOInvoiceEntry
// Example copying Description

protected void _(Events.RowPersisting<ARInvoice> e)
{
   var query = new SelectFrom<SOOrder>
      InnerJoin<SOInvoice>.On<SOInvoice.sOorderType.IsEqual<SOOrder.oderType>.
      And<SOInvoice.sOOrderNbr.IsEqual<SOOrder.orderNbr>>>
      Where<Use<SOInvoice.refNbr>.AsString.IsEqual<@P.AsString>>.
      View(Base);

   SOOrder so = query.Select(e.Row.RefNbr).TopFirst;

   so.OrderDesc = e.Row.DocDesc;

   Base.Caches[typeof(SOOrder)].Update(so);
   if(Base.Caches[typeof(SOOrder)].Updated.Cast<SOOrder>().Count() > 0)
   {
      Base.Caches[typeof(SOOrder)].Persist(PXDBOperation.Update);                    
   }   
}

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • October 19, 2022

Hi @Leonardo Justiniano ,

Thank you very much for your answer.

I am a newbie for Acumatica so I don’t have much knowledge about this, I have a concern that why don’t we use event FieldUpdate? It should be more efficient than an event on Row (e.g: RowPersisting)

 

Regards,

Khoi


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi @mrthanhkhoi 

FieldUpdated event is triggered when, indeed, a field value has changed. It is not a matter of efficiency. In my example I am saying that the description will be copied “only” when the invoice is saved. This way I  guarantee that I will have the last value specified by the user copied over.

I suggest you engage in the training courses provided by Acumatica where all these details are explained with really good examples and exercises 

https://openuni.acumatica.com/courses/development/

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • October 19, 2022
Leonardo Justiniano wrote:

Hi @mrthanhkhoi 

FieldUpdated event is triggered when, indeed, a field value has changed. It is not a matter of efficiency. In my example I am saying that the description will be copied “only” when the invoice is saved. This way I  guarantee that I will have the last value specified by the user copied over.

I suggest you engage in the training courses provided by Acumatica where all these details are explained with really good examples and exercises 

https://openuni.acumatica.com/courses/development/

 

Thank you very much for your help.

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings