I writing an in-transaction BPM on the ShipDtl table and would like to access a UD field on the PartLot table. I am sure I can write a query that will link the Partlot and Partlot_UD tables using the Company, PartNum & LotNum of the context but I was wondering if there was a “shortcut”.
For instance, I know I can get something from the Partlot table using “var Frozen = Db.PartLot.Where(…)” but why can’t I do the same with the Partlot_UD table like var Frozen = Db.PartLot_UD.Where(…)"
Db.PartLot will include the UD fields defined on PartLot_UD. You will need to access them using either of the following accessors:
var myValue = Frozen.UDField<TypeOfYourUDField>("NameOfYourUDField");
var myValue = Frozen["NameOfYourField"].ToString(); // Use Convert methods if it's an Int, Decimal, Boolean, etc.
The UD field is called isFrozen_c and it is on the PartLot_UD table so this is the code I wrote:
var txt = Db.PartLot.Where(p => p.LotNum == ttShipDtl_xRow.LotNum).Select(s => s.isFrozen_c).First();
But I still get an error message when I save the BPM:
Error CS1061: ‘Erp.Tables.PartLot’ does not contain a definition for ‘isFrozen_c’ and no extension method ‘isFrozen_c’ accepting a first argument of type ‘Erp.Tables.PartLot’ could be found (are you missing a using directive or an assembly reference?)
I did another regen and restarted all the services and now I am good: var txt = Db.PartLot.Where(p => p.LotNum == ttShipDtl_xRow.LotNum).Select(s => s.isFrozen_c).First(); worked.
The only differences would be:
You are selecting an additional field
You are doing FirstOrDefault() which can return a NULL value. First() with throw an Exception if no record is found.