Get UD field in in-transaction BPM

Hi,

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(…)"

Thank you,

Daniel

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.

Edit – See the post linked here: BPM and UD field questions/issues - #2 by jgiese.wci

1 Like

This is not working Frozen is the name I wan to give to the value of the UD filed, not the table name.

In BPM context, he is saying you dont need to access a UD table,just the main table.

var Frozen = myttRecord.UDField<bool>("Frozen_c");
or
var Frozen = Db.Part.Where(p => p.PartNum == myPartNum).Select(s => s.Frozen_c).First();

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?)

Then do this:
var txt = Db.PartLot.Where(p => p.LotNum == ttShipDtl_xRow.LotNum).Select(s => (bool)s[“isFrozen_c”]).First();

Also, are you sure your UD table is in the DB and Synced? Have you restarted your client since the regen?

1 Like

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.

Thank you both for your help!

1 Like

@Chris_Conn,
is that differ than
select new { s[“isFrozen_c”], s.StdField }).FirstOrDefault(); ?

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.

1 Like

many thanks mate, really appreciate your enlightenment :ok_hand:

1 Like