Skip to main content
Answer

Pass value of custom field from SO to Invoice

  • November 11, 2021
  • 6 replies
  • 877 views

xkylewrightx
Varsity III
Forum|alt.badge.img

Hello--

Was wondering if anyone can give me a hand with this… We essentially want an exact duplicate of the Description (OrderDesc) field that is already on sales order/invoices.

I have created a new field on each entry screen, but am stuck trying to pass the value from the SO to the invoice.

I assume I should override the PrepareInvoice action, but not sure how to actually reference the fields I have created? 

 

I.e. This is as far as I got but i know “  ThisNewInvoice.CustomerSubject = row.CustomerSubject; “ is obviously wrong

 

Any help is appreciated!!

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{

[PXOverride]
public IEnumerable PrepareInvoice(PXAdapter adapter, Func<PXAdapter, IEnumerable> baseMethod)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);

var row = (SOOrder)e.Row;

ThisNewInvoice.CustomerSubject = row.CustomerSubject;


return baseMethod(adapter); // and then return
}

 

Best answer by Dmitrii Naumov

I think you may find that slide deck useful. 

 

Also, you need to know several things:

  1. To access custom field you need to use GetExtension method. See here: https://riptutorial.com/acumatica/example/27596/how-to
  1. In general a Sales Order is not related 1-1 to an invoice. You may have several invoices prepared for the same sales order (e.g. in case of partial shipping) or you can have multiple sales orders  consolidated in one invoice. Or you can have any mix of them. So you need to take that into account when developing that customization.
  2. You don’t really have the access to the Invoice that is created from the PrepareInvoice method. The proper place for such customization is SOInvoiceEntry.InvoiceOrder method. From that method you have the access to both the SO and the invoice. Also, that method is triggered for all the scenarios when the Invoice is created from a Sales Order while PrepareInvoice method only works when you click that button directly on the Sales order screen.

6 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • November 11, 2021

I think you may find that slide deck useful. 

 

Also, you need to know several things:

  1. To access custom field you need to use GetExtension method. See here: https://riptutorial.com/acumatica/example/27596/how-to
  1. In general a Sales Order is not related 1-1 to an invoice. You may have several invoices prepared for the same sales order (e.g. in case of partial shipping) or you can have multiple sales orders  consolidated in one invoice. Or you can have any mix of them. So you need to take that into account when developing that customization.
  2. You don’t really have the access to the Invoice that is created from the PrepareInvoice method. The proper place for such customization is SOInvoiceEntry.InvoiceOrder method. From that method you have the access to both the SO and the invoice. Also, that method is triggered for all the scenarios when the Invoice is created from a Sales Order while PrepareInvoice method only works when you click that button directly on the Sales order screen.

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • November 12, 2021

@dnaumov This is very useful, thanks a lot for sharing it here.


xkylewrightx
Varsity III
Forum|alt.badge.img
  • Author
  • Varsity III
  • November 12, 2021

Thank you @dnaumov this looks like it will be really helpful. Going to work through it a bit before closing thread


Forum|alt.badge.img+5
  • Jr Varsity II
  • November 12, 2021

There is also an InvoiceCreated method that gets called after the invoice is created inside the InvoiceOrder method if I recall correctly. 

public void InvoiceCreated(ARInvoice invoice, SOOrder source, InvoiceCreatedDelegate baseMethod)

You can then pull over any info from the source SOOrder to the ARInvoice. 


Forum|alt.badge.img
  • Jr Varsity II
  • October 28, 2022

Hi @Dmitrii Naumov ,

Could you please share source code in the GIT again? 

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • October 28, 2022

@mrthanhkhoi  I’m afraid I don't have the code anymore. There are some code snippets in the slides, probably you can use those.