Page 1 of 1

Copying custom values from SO to Credit

PostPosted: Tue Jul 20, 2021 10:43 am
by pricerc
I feel like I might be missing something obvious...

When copying a quote, I can handle SalesOrder_Created and get the source quote to populate a S/O's custom fields.

How do I copy custom data to a credit note when creating one from a sales order?

Re: Copying custom values from SO to Credit  Topic is solved

PostPosted: Tue Jul 20, 2021 11:53 am
by Mike.Sheen
pricerc wrote:I feel like I might be missing something obvious...

When copying a quote, I can handle SalesOrder_Created and get the source quote to populate a S/O's custom fields.

How do I copy custom data to a credit note when creating one from a sales order?


When a credit note is created from a sales order, the CreditNoteInvoiceHistoryID and CreditNoteInvoiceID properties contains the values of the sales order you created the credit note from.

So, in a handler of the Created event, you can inspect the NewSalesOrderType parameter and if it is e_NewSalesOrderCreditNote, and the CreditNoteInvoiceHistoryID is not null or empty, then you know you're a credit note created from a sales order and the CreditNoteInvoiceID is the SO_Main.InvoiceID and the CreditNoteInvoiceHistoryID is the SO_History.InvoiceHistoryID of the sales order.

We don't have the whole sales order as a parameter to the Created event like we do with when making a sales order from a quote, unfortunately, but it will be easy enough to create a new sales order business logic instance and read that with the CreditNoteInvoiceID and find the snapshot with the matching CreditNoteInvoiceHistoryID.

Re: Copying custom values from SO to Credit

PostPosted: Tue Jul 20, 2021 12:04 pm
by pricerc
Thanks Mike.