Help BPM C# If Then Statement

I am trying to do a simple if statement in a BPM but it throwing an error when I check syntax “Invalid expression term ‘||’”. Any suggestions?

if(Customer[“CustShortName_c”] == “LOWESCNDC”) || Customer[“CustShortName_c”] == "LOWESCODC ")
{

You are closing the if statement too early, right before the ||.

if(Customer["CustShortName_c"] == "LOWESCNDC" || Customer["CustShortName_c"] == "LOWESCODC ")
{
//do stuff
}
1 Like

Also… if this is in a BPM, there is no need for the references to the UD Fields done this way… instead you can directly reference them. When you directly reference them, you also get program validation when you save.

if (Customer.CustShortName_c == "LOWESCNDC" || Customer.CustShortName_c == "LOWESCODC ") {
    //do stuff
}

ALSO, if your list of exceptions gets much longer, you can also change it to this:

var shortNameList = new List<string>() {
    "LOWESCNDC",
    "LOWESCODC",
    "LOWESABCD",
    "LOWESEFGH"
};

if (shortNameList.Contains(Customer.CustShortName_c)) {
    //do stuff
}

(I think i did that right… haha)

3 Likes

Just to clarify what @timshuwy said. This is true, but only in data directives. If using a method directive and accessing a tt ud field you must use something similar to what @Jason_Woods posted.

Here is the official Epicor verbiage - might be a little dated.

2 Likes

Dan,

I believe that’s true, but only with the tt tables. This is a reference to the Customer table, so Customer.CustShortName_c should work in both method and data directives.

Brian - one other thing to watch out for is if your data can contain mixed case. I don’t know all the specifics, but I always include an upper case as part of the compare: Customer.CustShortName_c.ToUpper().

Kevin

Yep - that is why I stated the following.

I have also seen people do things like this…

foreach (var Customer in (from row in ttCustomer) { blah blah }

You can never tell the context sometimes in a message thus the clarification.

Ughh…thanks. I guess I was just tired on Friday and not seeing what was right in front of me.