How to select from the database and respect segmented Key

Viewed 25

I would like to select from the database using a PXSelect and then receive a value that respects the segmented key.

Example:

var item = InventoryItem.PK.Find(graph, someInventoryID);
string inventoryCDRespectingSegmentedKey = SomeClass.SomeMethod(item.InventoryCD); // InventoryCD is a string value without the separators defined in the Segmented key at this point
1 Answers

I am not sure if this is the best way to get the value respecting segments or not, but this is how I do it usually.

if (row.InventoryID != null)
{
    var item = InventoryItem.PK.Find(sender.Graph, row.InventoryID);
    if (item != null)
    {
        var inventoryCDRespectingSegmentedKey = sender.Graph.Caches[typeof(InventoryItem)].GetValueExt<InventoryItem.inventoryCD>(item) as PXSegmentedState;
        PXTrace.WriteInformation($"{inventoryCDRespectingSegmentedKey.ToString()}");
    }
}
Related