How to do a BPM that throws an error if a RegEx variable does not contain (or match) numeric values

Hello Everyone,

I am very new to Epicor and am trying to do a BPM for validating fields based on if the user inputs numeric values, #, * or brackets and if those values are input it will raise an error exception. This is being done in a pre-processing method directive.

At the moment I have made the following condition below:

The usings I have put in are system and system.text.regularexpressions.

The argument variable I set (cannot find regex type) is of type System.String

The error I get when trying to match Regex (as it is obviously not the right type!)
"Result of expression canot be assigned to variable of ‘System.String’ type

and the custom C# I have put inside the editor is: Regex.IsMatch(dsCustomerRow.Name, “^[0-9]*$”)

The first condition successfully raises an exception when those values are input by the user, however I want to include numeric values to and due to my lack of knowledge of Epicor I don’t know how to set a variable to type RegEx as it doesn’t give you the option to do so (or not that I know of) and pass that through in the BPM.

Any help is greatly appreciated!

Yeah, that’s a no go with the widgets.

I think with enough finagling you could make it work completely with widgets, but I would do something more along these lines. Minimal custom code.

Create a variable:

Add a dash of code:

Check your variable:

Do something with it:

Some starter code:

//Check Matches Section
//This is just meant to be a starting point or framework...

  string pattern = @"^[0-9]*$";

  Regex rx = new Regex(pattern);
  
  foreach(var dsCustomerRow in ds.Customer.Where(cust => cust.RowMod == "U" || cust.RowMod == "A").ToList())
  {
      if(rx.Matches(dsCustomerRow.Name).Count() > 0)
      {
          MatchFound = true; //This Variable is set in the Widgets!!!
      }
  }
2 Likes

Thank you! I have attempted to implement that logic however it still doesn’t register the error exception. I changed the RegEx to contain brackets also, the regex now reads: string pattern = @“^[0-9*()#+]+$”; I don’t think it has anything to do with the pattern match as that seems correct to me, plus I validated the BPM and it successfully validates.

I added a condition at the start: “The ds.Customer.Name field of the changed row is equal to “an empty” expression” whichif true then rolls on to the custom code, still no result.

I was messing around with other method directives and noticed when I changed the order and tick the box “enabled” some error logs finally worked, I’m thinking that could be the case. What does that actually mean in the context of the method directive? Super new to EpiCor so still learning a bunch.

image

Thanks!