I am trying to pull the second to last record from the partTran table and specifically set the BPM context field equal to its attribute set short description. Does anyone know how to do this in a data directive?
Not sure how to get to the attribute set, but you can isolate the second latest record in PartTran with
var ptSecondLatest = Db.PartTran.Where( x => x.Part == "myPartNum" ).OrderByDescending( x => x.TranNum ).Skip(1).First();
Hi Kve, I get this error when I try and use this code. Any advice?
System.Drawing.Bitmap CS1061 âPartTranâ does not contain a definition for âPartâ and no accessible extension method âPartâ accepting a first argument of type âPartTranâ could be found (are you missing a using directive or an assembly reference?)
Ach, my apologies, the field is PartNum
, not Part
, so the correct statement is
var ptSecondLatest = Db.PartTran.Where( x => x.PartNum == "myPartNum" ).OrderByDescending( x => x.TranNum ).Skip(1).First();
This worked great, thanks!
Glad it worked!
Would you know how to select only transaction type âADJ-QTYâ and order that dataset and pick the second latest one?
Sure, just add it the the âWhereâ method:
var ptSecondLatest = Db.PartTran.Where( x => x.PartNum == "myPartNum" && x.TranType == "ADJ-QTY" ).OrderByDescending( x => x.TranNum ).Skip(1).First();
Or if you donât want to also filter by PartNum:
var ptSecondLatest = Db.PartTran.Where( x => x.TranType == "ADJ-QTY" ).OrderByDescending( x => x.TranNum ).Skip(1).First();