BPM for PO Approval

,

Im working on building a BPM for Po approvals when there is more than 1 level of approvals. i already have a BPM set up for the first level.
I am building it on the POApvMsg Table when the MsgTo field is changed and the MsgType is ‘1’
my issue is getting the Email address from the PurAgent table associated with the buyer ID in the MsgTo field.
Below is something similiar to code provide by a peer on spiceworks that i changed the tables, but i am new to C# and need help…

var ttPOApvMsg_xRow = ttPOApvMsg.FirstOrDefault();
var PONum = Convert.ToInt32(ttPOApvMsg_xRow[“PONum”]);
var POApvMsg_Row = Db.POApvMsg.FirstOrDefault(x => x.PONum == POApvMsg.PONum);
var PurAgent = Db.PurAgent.FirstOrDefault(y => y.BuyerID == POApvMsg_Row.MsgTo);

BpmContext.BpmData[“Character01”] = PurAgent.EMailAddress;

are you multi company?

if so you may want to include company in your queries.

are you getting an error?

how do you know your other queries are working as expected?

no not multi company

image

This line needs to be changed to
var POApvMsg_Row = Db.POApvMsg.FirstOrDefault(x => x.PONum == PONum);

1 Like

Are you using Method or Data directive? I had gotten some help form here before with the code and set it up using Data Directive. I just emailed Stephen :):wink:

its a standard data directive.

1 Like

here is the code that I am trying to use…it may help you.

Erp.Tables.PurAgent PurAgent;
foreach (var ttPOApvMsg_iterator in (from ttPOApvMsg_Row in ttPOApvMsg
where string.Equals(ttPOApvMsg_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase) || string.Equals(ttPOApvMsg_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase)
select ttPOApvMsg_Row))
{
var ttPOApvMsgRow = ttPOApvMsg_iterator;
foreach (var PurAgent_iterator in (from PurAgent_Row in Db.PurAgent
where string.Compare(PurAgent_Row.Company, ttPOApvMsgRow.Company, true) == 0
&& string.Compare(PurAgent_Row.BuyerID, ttPOApvMsgRow.MsgTo, true) == 0
select PurAgent_Row))
{
PurAgent = PurAgent_iterator;
callContextBpmData.ShortChar01 = PurAgent.EMailAddress;
}
foreach (var PurAgent_iterator in (from PurAgent_Row in Db.PurAgent
where string.Compare(PurAgent_Row.Company, ttPOApvMsgRow.Company, true) == 0
&& string.Compare(PurAgent_Row.BuyerID, ttPOApvMsgRow.MsgFrom, true) == 0
select PurAgent_Row))
{
PurAgent = PurAgent_iterator;
callContextBpmData.ShortChar02 = PurAgent.EMailAddress;
}
}

You might be able to reduce your lines of code.

How does this work?

 //Get Temp Record
var ttPOApvMsg_xRow = ttPOApvMsg.FirstOrDefault();
// Get Buyer of MsgTo on Temp Record
var PurAgent = Db.PurAgent.FirstOrDefault(y => y.BuyerID == ttPOApvMsg_xRow.MsgTo);
BpmContext.BpmData["Character01"] = PurAgent.EMailAddress;
1 Like

@knash That one line code change worked. thank you all for the help.

2 Likes

Hi Craig, I’m trying to do the same thing. Do you mind sharing your solution on how you did this?

In reality, your two queries here should have additional filter on Company to make it most efficient. Otherwise SQL has to hunt harder:

BUT to further improve this, since you only want ONE FIELD from each of those queries, you should tell sql to only return the needed field, and not then entire row. (Changes highlighted below)… it could be further improved by making the two queries into one joined query.

1 Like

Can you share the BPM workflow setup, we pasted the code into our Custom Code but it does not work, no email notifications are going out. we have the standard directive setup for notifying the buyer on the PO of approval or rejection status but the Approval Person needed is not receiving the emails. ?