Solved

Pass Custom Field From SOOrder to Invoice

  • 6 July 2023
  • 7 replies
  • 130 views

Userlevel 4
Badge

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?

icon

Best answer by darylbowman 7 July 2023, 14:15

View original

7 replies

Userlevel 7
Badge +10

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

 

Badge +11

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.

Userlevel 4
Badge

@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.

Userlevel 4
Badge

@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?

Badge +11

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;
}
}
}

 

Userlevel 4
Badge

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?

Badge +11

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.

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