BPM Argument Error

I created this BPM to run a query when we are shipping an Intercompany PO. If the job cost does not equal the cost on the order line, then I have the BPM stop the transaction. Which is does!

However, when we try creating a regular packing slip for a normal customer shipment I get the following error:

My BPM works as follows on the Cust.Ship.GetOrderRelInfo BO.

  1. At the Start I declare 3 variables (JobCost = Decimal, DocUnitPrice = Decimal, Linked = Boolean)
  2. Invoke BO method for the query name
  3. Invoke BO method for Getting the Query execution Parameters
  4. Execute Custom Code (Code screen shot below)
  5. Invoke BO method to Execute the Query and save results
  6. Set Argument/Variable for the My Linked Variable (Expression: Convert.ToBoolean(BAQResult.Tables[0].Rows[0][“OrderHed_Linked”]))
  7. Set Argument/Variable for Job Cost (Expression similar to above but for decimal)
  8. Set Argument/Variable for DocUnitPrice (Expression similar to above but for decimal)
  9. Condition: If Linked (Intercompany PO) is = True
  10. If Step 9 is True then, Condition: JobCost Argument is not equal to DocUnitPrice
  11. If step 10 is True, Send Email to Order Team.
  12. After email, Raise Exception Stopping transaction.

Here is the flow of the BPM.

Here is the custom code:

Any ideas to why my BPM errors out on normal customer shipment and not intercompany PO shipments? Is the BPM actually failing at the Set Argument Error where I declare my first argument?

The error is “There is no row at position 0” which is likely referring to your call to Parameters.ExecutionParameters[0]. There’s no rows in the set, so row[0] is eating it.

Make sure you’re properly initializing your Parameters object before calling it. The widgets don’t always do this. Check Parameters.ExecutionParameters.Rows.Count, and if zero, populate your rows rather than merely updating them.

Sidenote: I tend to package complicated BPM’s like this into functions. Not only does it make it easier to locate complex code, but I can also go into the Swagger page and test the outputs. Literally used this yesterday to figure out why I was getting a null object ref error. Turns out, again, the UI/widget wasn’t properly initializing things.

@jtownsend but I’m confused as to why this BPM doesn’t fail when the Set Argument/Variable to Linked (Intercompany PO) being true and runs through the remaining conditions with no error? I would expect it to fail on both instances.

How do I setup the Parameters.ExecutionParameters.Rows.Count? The code I got was from a previous BPM where I recycle it for instances like this, running BAQs to test against conditions. I’m not the best C# coder… I konw enough to be dangerous. In this instance harmless :slight_smile: .

And I’ve never used the Epicor Functions widget before. I probably need to learn it though!

It might also fail on Convert.ToBoolean(BAQResult.Tables[0].Rows[0][“OrderHed_Linked”])) Basically, anywhere you used Rows[0] is a candidate.

Any time you’re directly accessing an index like that, you should encapsulate it in a if(…Rows.Count > 0) block. The Count property is updated every time a row is added or removed to a collection object in .net. It’s like Array.Length. You don’t set it directly. You just modify your collection.

If you want some homework, look up Microsoft’s documentation on System.Collections.Generic and System.Data. Basically everything in Epicor is downstream of that.

I would suggest that, since you’ve already had to resort to a custom code block, you consolidate some of the widgets down into said code block. Frankly, more than a half-dozen widgets starts to get less readable than code too.

John, I’m going to take a look at your advice. I appreciate it. When I started this test, I had my query looking at Linked Orders (criteria on Order_Head, Linked = 1). The reason I was getting that error on a normal customer shipment was because it wasn’t linked :woozy_face:. My bad on that part. My next issue was the calculated field returning a null value. After I got all that squared away, the BPM started functioning properly for both Linked and Non Linked SOs. I