Solved

Event Trigger FieldUpdate: Copy Invoice Note to Sales Orders

  • 18 October 2022
  • 4 replies
  • 169 views

Userlevel 3
Badge

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.

icon

Best answer by Leonardo Justiniano 18 October 2022, 18:22

View original

4 replies

Userlevel 6
Badge +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);
}
}

 

Userlevel 3
Badge

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

Userlevel 6
Badge +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/

 

Userlevel 3
Badge

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved