Hot do I return a query result set as a variable in BPM Workflow designer?

##I’m working on a BPM that generates an email from the Project Entry module. When the user creates or updates a project and clicks the “email notification” button, an email goes out to various persons with the following:

The section with the order details will require multiple lines to be returned and output in the email body. I have it coded like this:

​​​

And when I check syntax, I get the error “Member declaration is not allowed inside code block.” I’ve tweaked it a few different ways, such as using COUNT(*), which resulted in the editor telling me that ‘COUNT’ does not exist in the current context.

However, when I comment out the section about the MaxLine variable, hardcode the number of lines I want, i.e. while (i <= 8), run the email, I get this:

And then when I add the FirstOrDefault() method, I get the output I want.

Of course, I chose the number 8 in the while loop above because I already knew there are 8 lines of data. Obviously, I can’t hard-code the number of lines I want returned. The loop has to be bounded by the number of rows queried, which varies by project. And yes, the same principle will have to be applied to the Misc Charges and Job Number sections.

Is what I want possible? Help and suggestions are appreciated.

Thanks.

Probably the simplest method using your existing code is to use .ToArray() in your db select and iterate through that to build your strings. Something like this should work

# code block
var details = (from x in Db.OrderDtl
			  where x.OrderNum == OrderNum
			  && x.Company == "DCS"
			  select x).ToArray();
if ( details != null  )
{			  
	foreach ( var detail in details )
	{
		// build detail string here, detail.PartNum, detail.LineDesc, etc.
	}
}

This worked, many thanks!