Epicor10 bpm Question

I’m gonna create an bpm which can send the email with Pack ID and Job Number when Pack ID in Subcontract Entry has been created

.
Pack ID belongs to SubshipH table, and Job Num Belongs to SubShipD table.
I was trying to add fill by query in bpm, but it doesn’t work.
Can anyone advice me to do it?

thank you very much

Can you post screenshots of your BPM so far?

You could create a variable, and set it with something like the following expression:

Db.SubShipD.Where( r =>r.Company == MyCompany && r.PackNum == ttSubShipH.Packnum && r.PackLine == 1).Select( r =>r.JobNum).DefaultIfEmpty("Not Found").FirstOrDefault()

(I took a few guesses with the actual field names you need from SubShipH and SubShipD.)

Then reference that variable in the email body.

2 Likes

Thanks for your response.
Here is my current bpm.
I’m not sure how to complete the mapping in ‘‘fill table by query’’.

First Email Notifications are best to be put in Data Directives Maintenance under the “Standard” tab. Its meant for Notifications, Messages, Auditing, Logging etc…

2 Likes

Thank you so much. Where should I create this variable?

As already stated, move your BPM to a Data Directive on the Standard. Then your directive would use a Condition to monitor the field PackNum. If conditions are met you could use a “Execute Custom Code” caller to query the SubShipD table similar to above and then something like this to send the email.

        var mailer = this.GetMailer(async: false);

        var message = new Ice.Mail.SmtpMail();
        message.SetTo("some.user@companyabc.com");
        message.SetFrom("noreply@yourcompany.com");
        message.SetSubject("Whatever you want in Subject line!");
        message.SetBody(strBody); //You could use the query above to build your Message Body and pass it in.
        mailer.Send(message);

In this example we are sending a Ship Confirmation when the ShipHead.ShipStatus changes from anything to “Shipped”.

Click the arrow then give it a name and a type (JobNums are actually strings)

Then the Set Arg/Var widget

1 Like

Thanks a lot! But I don’t really understand how did you fill the Specify #C Expression?

Credit for that expression goes to @josecgomez.

Here’s what each part does.

Db.SubShipD.Where( r =>r.Company == callContextClient.CurrentCompany && r.PackNum == ttSubShipHRow.PackNum && r.PackLine == 1).Select( r =>r.JobNum).DefaultIfEmpty("Not Found").FirstOrDefault()

Db.SubShipD - This is the table that holds the data you want.

.Where( ...) - These are the conditions to select the record(s) you want.

r - this is the reference to the row(s) that you want.

r.Company == callContextClient.CurrentCompany - this makes sure the record belongs to the company currently in use by the BPM

r.PackNum == ttSubShipHRow.PackNum - this makes sure the record belongs to the PackNum specified by the BPM’s temp table ttSubShipHRow (this holds a temp copy of the data being written to DB).

r.PackLine == 1 - This limits the record(s) selected to the first PackLine

.Select(r =>r.JobNum) - the value to be returned (JobNUm of the SubShipD table record that met the “Where” conditions)

.DefaultIfEmpty("Not Found") - Value to return if no records met the “Where”. This is optional.

.FirstOrDefault() - Instruction to return just one record. Either the first if one is found, or a default record if none exist. I’m guessing that “defaul” part would never happen since we also specify the “DefaultIfEmpty”

An important note to point out. Since there can be many SubShipD records for a given PackNum, multiple records could exist. The r.PackLine == 1 condition was added so it only ever returns the first. This might be unnecessary, as we use the .FirstOrDefault() instruction.

Note that if a line was added to the packer (it would be Line 1), and then a second line added (it would be Line 2), and then the first line deleted, there might be no SubShipD record for that packnum with PackLine =1.

Also if the Packer has multiple lines, it wouldn’t include the others.

1 Like