Email directive when shipdate is updated

I am trying to create a method directive to send an email to the customer when the shipdate field is updated. Problem I am having is getting the customer contact email to put as the “to” field in the send email.

“customer contact email” is actually a bit vague, as there are many that could be considered the email to use.

Having said that, you could set a variable with code to query the Customer or CustCnt table. Then use that variable as the “To:” field.

edit

the code for the set variable expression would be something like:

Db.Customer.Where( r =>r.Company == CurrentCompany && r.CustNum == ttShipHead.CustNum).Select(r=>r.EMailAddress).DefaultIfEmpty("").FirstOrDefault();

That just fetches the one email on the customer record. You’d need to get a little creative to chooses a specific Customer Contact

You would need to access the table containing the emails. It would be the contacts table. (CustCnt) There can be multiple contacts per customer. There is a choice of primary contacts to setup when adding a contact in the Customer Maintenance/Contact tab:
image

In your BPM, (I would use a Code Widget…) you would need to read the customer table, where the field PrimSCon (Primary shipping contact) is set.
then read the CustCnt table passing your customer number and the contact number in PrimSCon retreive the contact info where the email would be in EMailAddress field.

Use CallcontextBPMData to save the email and use it in the email widget.

Pierre

A closer look shows that you’re doing this in CustShipment.

A couple of caveats …
The ShipHead.ShipDate defaults to todays date. If someone creates the packer, then realizes it won’t ship until tomorrow, and sets the shipdate for tomorrow, it will fire.

You might be better off triggering on the ShipStatus field going from ANYTHING to SHIPPED.

Since a packer could be for more than one order, there could be more than one CustContact specified. In fact, different lines or releases on the same order could have different contacts specified.

So if I put a data directive on the OrderHed table to send an email to CustCnt_EmailAddress everytime OrderHed.RequestDate is updated, what would the custom code look like to get the CustCnt.EmailAddress?

Which contact from the OrderHed? There are many to choose:
PrcConNum (Purch Contact), ShpConNum (Shipping Contact), BTConNum (Bill To), OTSContact

assuming it was the Purchasing contact:

Db.CustCnt.Where( r =>r.Company == CurrentCompany && r.CustNum == ttOrderHed.CustNum && ConNum == ttOrderHed.PrcConNum).Select(r=>r.EMailAddress).DefaultIfEmpty("").FirstOrDefault()

Something like that. Not tested, so might be some syntax errors in there.