How can you iterate / loop in a BPM if you can't use C# blocks

For example, lets say when a certain field on the sales order change, if OrderHed_ShortChar02 = “A”, find all other sales orders with the OrderHed_ShortChar02 = ‘A’ and change the same fields on each of them.

The first thing that comes to my mind is a loop - but I can’t use c# blocks. Is there another way to do this? Perhaps there is some way to make a recursive BPM?

Tbh, I don’t understand why they don’t have blocks for looping, it doesn’t seem like it would be hard to add. Maybe its to prevent you from locking up the server?

I’m far from an expert here, but if you are concerned with the validation error on a BPM loop, I can tell you it’s a lie:

1 Like

I can second that. I regularly use looped BPM widgets. You have to know that Epicor doesn’t care if you make an infinite loop. So you have to be very careful about your loop conditions. I use the conditionals, internal variables, and set value widgets. I don’t ever bother to ‘validate’. It just seems to take forever and never give any useful information. If the BPM will save then it should be ok.
Good luck!

1 Like

Ok, can you give an example of changing a field on a bunch of records returned by a query? I can see how you might increment a number, so you could recreate a “For” loop, but I can’t figure how you would access query results by index.

I can’t help with your exact issue. The best way I have learned is to first trace the steps you want to reproduce in the BPM. This isn’t exactly what you want, but some of it might help.

In my case I wanted to create a new line/release. So I opened the sales order entry form, navigated to my sales order. Then I started the tracer in Epicor. Go back to sales order form and create the new line/release. Go back to the tracer and stop the trace, and open the trace file.

I think you might want a method-directive. But not sure on the details. Change Op Description When Switching Resource Group IDs

For reviewing trace data I can’t recommend Jose’s trace utility enough!

I’m a big fan of BPM widgets. Although I’m on-prem now, I’m anticipating going to the cloud some day (maybe for E11?). They can do a lot, if you get into the mindset.

To accomplish your initial use case, I think this would work:
-Create a new OrderHed tableset variable
-Use Fill Table by Query to populate that table with all the OrderHed’s that have ShortChar02 = “A”
-Use Set Field to change ShortChar02 to “B” in all rows
-Use Invoke BO Method to run Erp.Order.UpdateExt using the edited tableset variable.

2 Likes

I’ll give that a try tomorrow. What determines what variable types you can make? There have been times that I wanted to create a certain kind of tableset and it wasn’t available for selection.

When defining a new variable, in the Type dropdown, select Choose Type and a window pops up that allows you to choose from among hundreds of categories of assemblies. I usually pick Erp.Contracts.BO. then the particular BO that I intend to call, such as BO.Part. Then the appropriate tablesets for that BO are shown in the list.

Alternately, if you start by defining a new query inside a Fill Table By Query that references a new table, such as Erp.Part, then when you go back to the Variables tab and define a new variable name, the PartTableset is now in the Type dropdown.

1 Like

Okay, I was able to get my first example to work with the fill table and Erp.Order.UpdateExt like you suggested. Now I have another situation where I can’t find the block to do what I want…

Order 8005 (Parent)
Order 8011 (Child 1 ShortChar02 = 8005 )
Order 8013 (Child 2 ShortChar02 = 8005 )
Order 8015 (Child 3 ShortChar02 = 8005 )
Order 8022 (Child 4 ShortChar02 = 8005 )

Now I want to make a BPM such that if order 8005 is closed/deleted/etc then 8011 becomes the new parent. At first I figured it would be easy, just take the first row of the query where ShortChar02 = 8005 to get the new parent number, and then use fill table to update them all to 8011.

I can’t figure out how to get the first result, would be so easy if I could use LINQ or probably even if I could use the full BAQ options, but the BPM query options are so limited.

Is there any way to do this with the darn blocks?

I think I might have found a way, you can slip in little bits of code with the set variable block like so:

Very nice solution.