Skip to main content
Answer

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

  • February 24, 2022
  • 3 replies
  • 1538 views

Forum|alt.badge.img+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

Best answer by markusray17

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

 

3 replies

Forum|alt.badge.img+5
  • Jr Varsity II
  • Answer
  • February 24, 2022

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

 


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • February 24, 2022

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.


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • February 24, 2022

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