BPM: Send Email

I have a BPM on the SalesOrder Update method that sends an email or our Purchasing group that a line quantity has been changed. This is to alert them if they need to adjust any POs.

Problem is, now they want the BuyerID from the PartPlant table added to the email but the BPM doesn’t have that table in this data set. I know I can use C# to get to the PartPlant table and even send an email via C# but it’s not optimal.

I thought about using a BPM variable but when I try the error is, “Expression should contain only one statement”

You can use a BPM Variable but you’ll have to populate the variable with some code…

2 Likes

Are you familiar with Linq to query a table?

In a BPM you could use the partnum to query the PartPlant table and return the BuyerID and assign it to a callContextBPMData field and plug that into the email.

When it says there are multiple expressions it means it’s only expecting a single value. Like 1, 2 or some sort of single query result. In the expression window when setting a variable you can try something like bellow. What the below is doing is grabbing the first result that matches the criteria and giving you the buyer id, if there is no result it just returns an empty string. Admittedly I didn’t test this but it should probably work.

Db.PartPlant.FirstOrDefault(p => p.Company == callContextClient.CurrentCompany && p.Plant =={put your plant here} && p.PartNum == {put part num here})?.BuyerID ?? ""
4 Likes

@Jeremy_Westbrook,

Thanks, I’m going to try the below with our users:

Db.PartPlant.FirstOrDefault(p => p.Company == callContextClient.CurrentCompany && p.Plant == "MfgSys"  && p.PartNum == dsOrderDtlRow.PartNum).BuyerID ?? ""

I’ve never set a BPM variable via a C# block of code though. Especially trying it as a single expression like @Jeremy_Westbrook gave me.

1 Like

@Jeremy_Westbrook your code worked perfectly!

2 Likes