Help with Syntax

,

Can anyone help here with the syntax. This has multiple records in it but I just want the highest line number. Thanks in advance.

ttOrderDtl.OrderByDescending(dtl => dtl.OrderLine).FirstOrDefault()?.OrderLine ?? 0

Try this. First it orders the rows by their OrderLine descending, so the row with the highest value is first. Then it gets the first row (or null if there are no rows) and pulls the OrderLine value from that row if it exists. The ?? 0 will return a default of 0 in case there are no rows in the ttOrderDtl table.

1 Like

This worked perfectly !!! Awesome !!! Thanks for the coding experts here.

This worked perfectly !!! Awesome !!! Thanks for the coding experts here.``

image001.png

Depending on what kind of BPM this is in, temp tables might contain different things. For example (and from memory, so I might be missing something) in pre-processing, you get both old and new versions of modified rows. The new version will have RowMod=“U” and the old version will have RowMod=""; you can match them up with their SysRowID. On a delete, I expect pre BPMs would see the deleted row. That might affect your decision about the highest row number. IIRC, deleted rows will not be present at all in the temp tables in post. Also, after calling a GetNew but before calling Update, your dataset will contain a row with RowMod=“A” where OrderLine has not been assigned yet, destined to become the new highest value.

Very good points and important to keep in mind when building a BPM for edge cases. The code above would get the highest existing Line #, which as you said might not be correct after the business method is done.

You’re right about the deleted rows. They’re present in the pre-processing directive – with RowMod = “D”, but are not in the dataset in the post-processing after a call to Update.