External BPM references?

Happy Monday!

How would someone go about figuring out which files need to be included in a using statement for an external dll?

I’m trying to create a method that I can reuse in a different section of a BPM custom code block And needed to access Session.AppServerURL, Db.UserComp, Db.Device, & Db.SysPrinter.

Or maybe there is an easy way to create a reusable method in a BPM, other than a dll?

I am not sure, but I doubt a custom dll will be the best long term solution if it’s wrapping up Epicor assemblies, since you’ll have to recompile every time you upgrade and redeploy it to that folder.

Can you do the logic in a BAQ and call a dynamic query? I did that for setting scrap rates in BPM’s on change since having the BPM on update was problematic, and the On change I needed if for 2 different places. The stuff that would change is in the BAQ so I only need to maintain that in one place.

full disclosure @josecgomez and @hkeric.wci were the ones who introduced me to that technique.

1 Like

Can BPMContext be a friend here?

Full disclosure @josecgomez, @hkeric.wci, @Rich, or @timshuwy introduced me to this technique.

1 Like

1 Like

Adding support to this, if you use a uBAQ, you can pack a lot of reusable functionality into the code parts and call it from anywhere else in Epicor you like. If all the logic is Epicor logic, that’s far cleaner than an external dll.

External dlls can be useful, but in my experience they’re best suited for things which have nothing to do with existing Epicor functionality, and can work with nothing from Epicor except what is passed in as arguments.

1 Like

Thanks for the input. I may just end up passing in the Session, User, Printer values I need.

I’m just trying to reuse a block of code to generate a Bartender csv file, so it doesn’t have to be in the code in 8-10 different places… And since you can’t declare methods inside the BPM, it seems an external dll is the only option.

I did see something about C# actions, is that something that might work?

I totally agree that not being able to declare methods in a BPM is annoying, but a separate dll to avoid code repetition feels a bit sledgehammer/nut, though in practice you should be fine if it doesn’t need to reference any Epicor assemblies.

Sorry I can’t help on C# actions. Personally, when I can’t structure repeated code in some kind of loop in a BPM, I either grit my teeth and copy/paste, or pull out the repeated part into a uBAQ. If you do go that route it would be interesting to know how you get on.

We had a discussion about this at Insights at lunch one day where we discussed running Bartender on a local server, where all of your code would reside, and then in your BPMs, you would just call a web service to print. You would pass the printer, label type, and various parameters in. A cool side effect is that you could print labels on demand from a form in case one was damaged or your lost some.

Mark W.

Are these in different BPM’s? Or are you just talking about re-using the same method all within the same code block?

If it’s the latter, you can use action or func delegates. I just learned about them recently (thanks @josecgomez). But they basically can act just like declared methods. The syntax is a little confusing (I’m still working on understanding them) but they will do what you want.

Edit:
And of course If I would read your whole post, that is exactly what you are looking for,

Here’s a link to get you started.

1 Like

Thanks, Brandon!

I thought I remembered a similar post a while back, but couldn’t find it. Now that I know that the term I needed was C# actions & func delegates, I found the post I was remembering.

Glad to know I was on the right path.

Time to learn something new, I guess!

func\action delegates are useful in BPM, moderately. You still have many limitations like scope (within current bpm only), no access to local vars, not to mention writing a func to pass in more than a few vars can be tedious.

1 Like

Well, I guess I’ll mark today as a success!

I learned about C# Actions and managed to get it to work in my BPM. It’s a little messy, but it works:

Action<int, string, string, string, string, string, string, string, string, string> PrintLabel = 
	delegate (int qtyLabel_f, string ReceiptDate_f, string PONumLineRel_f, string PartNum_f, string PartDesc_f, string ReceivedTo_f, string NextStop_f, string QtyIUM_f, string WIPDemand_f, string changedBy_f)

I also managed to install and upgrade our test system to 10.2.400.2 :slight_smile:

Now it’s time for a beer! :beer:

4 Likes