Solved

How do I access a field I created in a DAC Extension?

  • 24 February 2022
  • 3 replies
  • 1035 views

Userlevel 5
Badge +1

I am trying to add a new field to the Sales Order Entry screen.  I created a new field as a DAC Extension:

namespace PX.Objects.SO
{
public class SOOrderExt : PXCacheExtension<PX.Objects.SO.SOOrder>
{
#region UsrCustomField
[PXString]
[PXUIField(DisplayName="Price Class ID", IsReadOnly = true)]
public virtual string UsrPriceClassID { get; set; }
public abstract class usrPriceClassID : PX.Data.BQL.BqlString.Field<usrPriceClassID> { }
#endregion
}
}

I have added the new field to appear on the screen of the Sales Order Form. I want to set the value of this field when the Location is changed.

I have the code to get the value I want to insert into it but I’m not sure how to access the field in the Event Handler under SOOrderEntry.

I tried: 

protected void SOOrder_CustomerLocationID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOOrder)e.Row;

if (row == null) return;

// Find the Price Class for the Customer

Location custLoc = PXSelect<Location, Where<Location.locationID, Equal<Required<Location.locationID>>>>.Select(Base, row.CustomerLocationID);

// Set the value of usrPriceClassID to the PriceClassID from Default Location for Customer

row.usrPriceClassID = custLoc.CPriceClassID;
}

It fails to validate as usrPriceClassID doesn’t exist under SOOrder.  I think I need to access it via the extension but I’m not sure how.

Thanks for any advice.

Phil

icon

Best answer by markusray17 24 February 2022, 20:18

View original

3 replies

Userlevel 6
Badge +5

To get the extension you need to call the GetExtension<ExtensionType>() method which exists on the SOOrder object as well as the Cache object.

var rowExt = row.GetExtension<SOOrderExt>();

OR

var rowExt = cache.GetExtension<SOOrderExt>(row);

 

Userlevel 5
Badge +1

I found the answer to my problem.

I needed to access the extension as:

SOOrderExt sOOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);

and reference it with:

row.UsrPriceClassID = custLoc.CPriceClassID;

I always get confused about which has the capital.

Working fine now.

Userlevel 5
Badge +1

To get the extension you need to call the GetExtension<ExtensionType>() method which exists on the SOOrder object as well as the Cache object.

var rowExt = row.GetExtension<SOOrderExt>();

OR

var rowExt = cache.GetExtension<SOOrderExt>(row);

 

I used a slightly different method but it was basically the cache one but more long winded. Thanks for showing me the correct way to do it.

 

Phil

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