How to trigger a script from BPM?

I have been tasked to create an email when a quote is marked Quoted.

I can create a BPM that does this and sends a primitive looking email (no HTML). However it can only send to ds.QSalesRP (ttQSalesRP). THere are no other email options like sales rep manager, inside sales manager, or outside rep and so on.

And of course they want it to be sent to a few more people for oversight.

I’m not good at programming inside BPMs, but can program outside with PHP scripts on our local network webserver. When I program with PHP I can create robust emails and meet all the end users requirements of who to send it to by querying the database. Are there any ways to call a url from inside BPM?

you can always just type the “to” address into that field and hard code in who you want to send the email to.
The reason to use the field/table values is if you’re sending it dynamically, but it doesn’t sound like that’s the case?
If you wanted to get clever you could always create local variables, set them via code, then set to “TO” to those variables.

image

Could also set/use call call context variables to store email addresses.

Additionally, you can definitely interact with urls via custom code block, but you’d have to write C#

1 Like

They want the following users emailed dynmaically: outside salesperson, inside salesperson, manager. The only one that can be hardcoded is probably the manager. So I have to query the database to get all those values because they aren’t in the BPM data. The best way I know how to do that is through a custom script.

Also is there a way to get HTML in the email? The emails I tested with didn’t honor the HTML, it just spit it out verbatim.

Re: HTML Yes you can but you need to use custom code.

Your best bet is either writing a simple bit of c# in a custom code block to query the information you’re looking to grab or I think there is a way to do it with the widgets (search the forum) but I’m not much of a widget guy

You can do simple HTML in a BPM Email widget …

Edit: scroll down to post #17 in the above link to see an example of a test I did

When you create a method directive or a data directive, Epicor generates the c# code on the server.

Find it, it will be a very good starting point if you want to create your own custom code. Don’t overwrite Epicor’s Code. Create your own stuff… when the situation needs it.

We have a very similar BPM for receipts. Email the relevant people when the items they ordered for jobs / sales orders arrive. I have used a data directive to trigger the processes. The BPM work flow is below.

The condition determines if an email needs to be sent. The custom code goes off and gets the relevant email address. In the custom code widget there is code like this to pull the email address from the database.

var email= Db.JobHead.Where(jh => jh.JobNum == job).Select(jh => jh.PersonID ).First();

If you are not familiar with C# linq syntax i will break it down…
Db.Jobhead means goto the database and get the JobHead table.
.Where(jh => jh.JobNum = job) means get the rows where the JobNum column equals job (job is a variable defined elsewhere in the code)
.Select(jh => jh.PersonID) means select the PersonID column
.First() means get the first record returned.

If you let us know where you need to pull the email address from I am sure we can help with the query needed.

I then stuff that in the BPM context variable.

callContextBpmData.Character01 = email;

And use it in the email widget.

Important note: in the BPM workflow there are 4 “Set BPM Data Fields” widgets. These set the callContext.Character0x feilds back to empty strings. For some strange reason that I don’t understand, without these the BPM crashes on the second time it runs!

Hope this is helpful
Brett

1 Like

I had a bunch of BAMs from E9 that I converted to scripts for E10. We don’t use quote so I don’t have one for that, but here is an example of one. I have a much simpler one Credit Hold that might be a better starting point.