Skip to main content

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

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


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