T-Rav
T-Rav

Reputation: 67

How to use PXSelect to get a user defined field? (AKA the ext fields)

I've added a few fields to the items table. I need to be able to reference those fields from code when the SOLine is updated.

I've got a PXSelect that works correctly, and gets me an InventoryItem, but clearly I need to be in the Ext section (AKA, return an InventoryItemExt) but I'm not clear how I make PXSelect do that.

This returns the item I need:

      InventoryItem iiTheItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, row.InventoryID);

But Fails here:

dQPI = Convert.ToDecimal(iiTheItemExt.UsrLbsPerInch);

If I make a variable as the ext it works syntax wise but obviously loads nothing.

InventoryItemExt iiTheItemExt = null;
dQPI = Convert.ToDecimal(iiTheItemExt.UsrLbsPerInch);

How to I bridge the PXSelect and the class I need? Thanks in advance!

Upvotes: 0

Views: 756

Answers (3)

Patrick Chen
Patrick Chen

Reputation: 1056

Assuming your extension is called InventoryItemExt...

 InventoryItemExt itemext = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(iiTheItem );

Upvotes: 1

Hugues Beaus&#233;jour
Hugues Beaus&#233;jour

Reputation: 8268

PXSelect is fine as is. You need to call the GetExtension method with the Base DAC record to obtain a reference to the DAC extension.

Here are some usage examples:

InventoryItemExt iiTheItemExt = iiTheItem.GetExtension<InventoryItemExt>();
InventoryItemExt iiTheItemExt = Base.Caches[typeof(InventoryItem)].GetExtension<InventoryItemExt>(iiTheItem);

Upvotes: 2

Joshua Van Hoesen
Joshua Van Hoesen

Reputation: 1732

Below is a code example that retrieves an InventoryItem based on a specified criteria, returns it and then accesses its declared extension.

            InventoryItemExtension itemExt;
            InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(this.Base, new object[] { "TEST" });
            if(item != null)
            {
                itemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExtension>(item);
                decimal? dQPI = Convert.ToDecimal(itemExt.UsrLbsPerInch);
            }

Upvotes: 0

Related Questions