Hello folks, I’m hoping someone has a thought on using variables to specify required parameters within a BPM’s foreach statement.
Specifically, the BPM determines the appropriate table and field names and stores them in variables. I’m trying to figure out how to then use those variables in the foreach statement…
if (relatedFile == “ShipHead”) {idField = “PackNum”;}
if (relatedFile ==“POHeader”) {idField = “PONum”;}
foreach (var record_Iterator in (from relatedFileRow in Db.relatedFile where relatedFileRow.idField == relatedID select relatedFileRow))
As you can see, the ‘foreach’ statement requires a table name and a column name (in the where clause). These elements are known before the foreach, but I can’t figure out how to insert those known elements into the statement using variables. My research thus far has lead me to topics like ‘Lambda’ and ‘dynamic filter expressions’ that are way over my head. Can anyone assist with this specific issue?
I may not have the perfect answer, but what about repeating the for/each, for each variable. I am not sure if this will work in your particular case. It might be worth a shot.
if (relatedFile == “ShipHead”) {
foreach (var record_Iterator in (from relatedFileRow in Db.ShipHead where relatedFileRow.PackNum== relatedID select relatedFileRow))
{//do for/each stuff}
}
if (relatedFile ==“POHeader”) {
foreach (var record_Iterator in (from relatedFileRow in Db.POHeaderwhere relatedFileRow.PONum== relatedID select relatedFileRow))
{//do for/each stuff}
}
Thanks very much for your feedback. As it so happens, your solution is exactly what I ended up doing (“great minds think alike”).
At some point I’d love to find that ‘perfect answer’, as the relatedFile variable can contain 31 different file names, so those foreach statements will add up. I think I’ll post this in the Code Review forum to see if some expert cares to step up to the challenge!
In any case, this is certainly workable and I appreciate you taking the time to respond!