Skip to main content

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.

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.Cachesetypeof(SOOrder)].Update(so);
if(Base.Cachesetypeof(SOOrder)].Updated.Cast<SOOrder>().Count() > 0)
{
Base.Cachesetypeof(SOOrder)].Persist(PXDBOperation.Update);
}
}

 


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


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/

 


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