Skip to main content
Solved

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

  • 24 February 2022
  • 3 replies
  • 1349 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);

 

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+5
  • Jr Varsity II
  • 237 replies
  • 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
  • 133 replies
  • 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
  • 133 replies
  • February 24, 2022
markusray17 wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings