BPM C# Code - Help Needed

I’m having an issue with C# code context within a BPM. There is a table set (tsWB) that stores multiple tables within it.

image

I need to be able to reference tsWB > ECORev > RevDescription. If I assign it via the “Set Argument/Variable” widget the verbiage is as follows:

tsWBECORevRow.RevDescription

If I try to reference this within the C# widget I get the following error:

image

What is the specific context needed to reference this field in C#?

I believe tsWBECORevRow is usually a variable name that is given.

Does your code look something like:

foreach (var tsWBECORevRow in tsWBECORev)
{
  myComment = tsWBECORevRow.RevDescription;
}

?
I believe your problem is that tsWBECORevRow is not declared anywhere in scope. Traditionally, it’s a variable that can be named anything else as well.
the following code would mean the exact same thing:

foreach (var row in tsWBECORev)
{
  myComment = row.RevDescription;
}

and it would reference the exact same row(s).
This snippet of code will iterate through all rows within tsWBECORev and you can address each row’s RevDescription field by using tsWBECORevRow.RevDescription, but it has to be within the foreach loop, because tsWBECORevRow is not declared anywhere outside of the loop.

If you want to use tsWBECORevRow’s contents outside of the loop, you can set some other variable equal to it. Here’s how you can do that:

var outsideLoopVariable; // outsideLoopVariable is declared before the loop
foreach (var tsWBECORevRow in tsWBECORev)
{
  myComment = tsWBECORevRow.RevDescription; // this is your code
  outsideLoopVariable = tsWBECORevRow; // sets outsideLoopVariable to the entire Row object
}
/* you can use outsideLoopVariable here, but in this context it will be set to the last iterated row. If you want it set to a specific row, you will need to "break" out of the loop when a certain condition is met.*/
1 Like

:safe_harbor: (Assuming this should be similar) I am not in Kinetic yet to provide the code to access the tableset tsWB data, but here is sample code of what @masuphiber is alluding to that you need in your code block(?) to access a dataset row versus a tableset column? by row?:

/// Grab data row to work with for BPM dataset in InventoryQtyAdj.SetInventoryQtyAdj / Pre-Processing
var dsInventoryQtyAdjRow = Epicor.Customization.Bpm.EnumerableExtensions.GetSingleRow(ds.InventoryQtyAdj, "ds.InventoryQtyAdj"); // Use Epicor std widget logic to grab single row.
1 Like