Skip to main content
Answer

Pass Custom Field From SOOrder to Invoice

  • July 6, 2023
  • 7 replies
  • 257 views

rcreasy
Varsity I
Forum|alt.badge.img

I have created a custom bool field on SOOrder. 
 

 #region UsrFreightRecovered
[PXDBBool]
[PXUIField(DisplayName = "Freight Recovered")]
[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]

public bool? UsrFreightRecovered { get; set; }
public abstract class usrFreightRecovered :
PX.Data.BQL.BqlBool.Field<usrFreightRecovered> { }
#endregion

This field indicates that freight charges are to be handled in a non-standard way. I need to present the fact that the custom field is true on the invoice header. 

From reading here, and attempting to code this, it seems that I have to pass the value to ARTran. The field needs to be immutable on the invoice, so I added it as a non-persisted string. I want to mark the value as true in the invoice header if any ARTran line has the value as true.

I am at a loss at this point. I have no idea how to access the the Order Nbr field for each detail line in order to look up the custom field value, or how to pass that value to the Invoice  header.

Can anyone point me to resources that may help me?

Best answer by darylbowman

Yes, that’s what I meant. You just don’t usually want to use FieldSelecting on a persisted field.

You should be able to do something like this:

protected virtual void _(Events.FieldSelecting<ARInvoice, ARInvoiceExt.usrCustomField> e)
{
ARInvoice invoice = e.Row;
if (invoice is null) return;

var invoiceGraph = e.Cache.Graph as ARInvoiceEntry;

foreach (ARTran tran in invoiceGraph.Transactions.Select())
{
SOOrder order = ARTran.FK.SOOrder.FindParent(invoiceGraph, tran);
var orderExt = order?.GetExtension<SOOrderExt>();
if (orderExt?.UsrFreightRecovered ?? false)
{
e.ReturnValue = "Freight Recovered";
return;
}
}
}

 

7 replies

Forum|alt.badge.img+9
  • Semi-Pro III
  • July 7, 2023

Hi @rcreasy ,

I got similar forums to answer your question.

Pass value of custom field from SO to Invoice | Community (acumatica.com)

Have you tried this?

Hope it helps!

Regards,

Sweta

 


darylbowman
Captain II
Forum|alt.badge.img+15

If you're using a non-persisted field (and only then), you should be able to use the FieldSelecting event to iterate through the ARTran lines and lookup the SOs by something like ARTran.SOOrderType and ARTran.SOOrderNbr. Then, set e.ReturnValue to the value you want.


rcreasy
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • July 7, 2023

@sweta68 Thanks. I did see that thread. I looked into using the SOInvoiceEntry.InvoiceOrder method. I am still trying to figure out how to do that.


rcreasy
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • July 7, 2023

@darylbowman Thanks again. You have helped me before.

The field is non-persisted on the invoice, but not on the SOOrder. I think that is what you mean?
I will look into using the event. I have to extend the merhod that handles the event, right?


darylbowman
Captain II
Forum|alt.badge.img+15

Yes, that’s what I meant. You just don’t usually want to use FieldSelecting on a persisted field.

You should be able to do something like this:

protected virtual void _(Events.FieldSelecting<ARInvoice, ARInvoiceExt.usrCustomField> e)
{
ARInvoice invoice = e.Row;
if (invoice is null) return;

var invoiceGraph = e.Cache.Graph as ARInvoiceEntry;

foreach (ARTran tran in invoiceGraph.Transactions.Select())
{
SOOrder order = ARTran.FK.SOOrder.FindParent(invoiceGraph, tran);
var orderExt = order?.GetExtension<SOOrderExt>();
if (orderExt?.UsrFreightRecovered ?? false)
{
e.ReturnValue = "Freight Recovered";
return;
}
}
}

 


rcreasy
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • July 7, 2023

I am still struggling with this issue. Slowly learning C# and Acumatica...

Here is my extension of ARInvoice

using PX.Data;
using PX.Objects.AR;
using PX.Objects.SO;

namespace CGCScreenMods
{
public class ARInvoiceExt : PXCacheExtension<PX.Objects.AR.ARRegister>
{
#region UsrFreightRecoveredInv
[PXString(5)]
[PXUIField(
DisplayName="Freight Recovered",
Enabled = false,
IsReadOnly = true
)]

protected virtual void _(Events.FieldSelecting<ARInvoice, ARInvoiceExt.usrFreightRecoveredInv> e)
{
ARInvoice invoice = e.Row;
if (invoice is null) return;

var invoiceGraph = e.Cache.Graph as ARInvoiceEntry;

foreach (ARTran tran in invoiceGraph.Transactions.Select())
{
SOOrder order = ARTran.FK.SOOrder.FindParent(invoiceGraph, tran);
var orderExt = order?.GetExtension<SOOrderExt>();
if (orderExt?.UsrFreightRecovered ?? false)
{
e.ReturnValue = "true";
return;
}
}
}

public string UsrFreightRecoveredInv { get; set; }
public abstract class usrFreightRecoveredInv : PX.Data.BQL.BqlString.Field<usrFreightRecoveredInv> { }
#endregion
}
}

without the method my field displays with the label and an empty value (I want to have a default of “false”)
The usrFreightRecoveredInv class definition looks wrong for non-persisted. But, I cannot find any info - it was generated in Acumatica.
With the method an empty text field with no label is displayed. Any thoughts/help?


darylbowman
Captain II
Forum|alt.badge.img+15

You want the FieldSelecting event in a graph extension, not with the DAC field in the cache extension.

You’ll want to extend the ARInvoiceEntry graph.