BPM Help on Condition

I’ve been at this now for approximately 3 hours and my forehead is bloody and I’m tired and nothing is working.

I am trying to do a Pre-Processing directive that counts the number of rows in 1 of the tables in the dataset that meets a criteria.

I tried using the “Number of rows in the designed query…” condition. I brought in the ttTable that I wanted to check and then applied criteria to it. When I entered the constant like text, I got a compile error. When I entered the constant like 'text', I got a compile error. When I entered the constant like "text", no compile error, but the BPM did not work as needed. (and I also thought you were just supposed to enter the constant without anything around it)

After that, I tried using “The custom code…” condition. I tried a whole bunch of different things, but none of them were working because I don’t know C# all that well. The closest I got to it working was:

foreach (var myHold in (from holdlist in ttBpHoldAttachment
where holdlist.HoldTypeID == "cust_xxxxxx"
select holdlist))
{
    if (holdlist.Count() = 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

These are the compile errors I get. image

Any help or hint in the right direction would be greatly appreciated.

John,

Which version of Epicor?

Mark W.

10.1.600.8

Dear John,

It appears that you are trying to go through a list of records that match a condition, but on the very first one you try, you’re executing a return which would not allow you to see the 2nd or subsequent matching records. If you really need to loop through “foreach” multiple records, and keep track of whether something has happened on one or all of them, and then return, I recommend changes similar to the code below. The way it’s written, the code will always return a value but the compiler can’t determine that.

Also I think the first error is that you’re checking the internal lambda expression value rather than the iterator. Below is my first attempt, but you might be able to return the test condition directly at the end to make it cleaner.

HTH

var varMyHoldFields = null;
int intTrueFlagsFound = 0;

foreach (var myHold in (from holdlist in ttBpHoldAttachment
  where holdlist.HoldTypeID == "cust_xxxxxx"
  select holdlist))
{
    varMyHoldFields = myHold;

    if (varMyHoldFields.Count() = 1)
    {
        intTrueFlagsFound++;
    }
    
}// end foreach

if (intTrueFlagsFound > 0)
    {
        return true;
    }
return false;
1 Like

@MontyMan Thanks for the response. I just got power back after the snow storm and will be playing around with what you sent. I already see where one of my mess ups was. Thanks for the input, I’ll let you know how it comes out.

@MontyMan Thanks for your help. I’m still very remedial at C# and your response pointed out a couple of things that I was doing wrong. I finally got everything working after running into a couple of more walls and wanted to let you know that I appreciated your input.