BPM help for PO approval

Hello
We’re using this code in a BPM-data directive
to get the purAgent email for a PO approval, but the problem is that is not considering the company code so now, we have same PO number but different company and the email is going to the first record that is not the correct company
I don’t know how to modify this code and add the criteria for the company
but i’ll really appreciate if someone can help me

var ttPOHeader_xRow = ttPOHeader.FirstOrDefault();
var PONum = Convert.ToInt32(ttPOHeader_xRow[“PONum”]);
var POHeader_Row = Db.POHeader.FirstOrDefault(x => x.PONum == PONum);
var PurAgent = Db.PurAgent.FirstOrDefault(y => y.BuyerID == POHeader_Row.BuyerID);
BpmContext.BpmData[“Character01”] = PurAgent.EMailAddress;

var Approver = Db.PurAgent.FirstOrDefault(z => z.BuyerID == PurAgent.ApprovalPerson);
BpmContext.BpmData[“Character02”] = Approver.EMailAddress;

Thank You

Try

var PurAgent = Db.PurAgent.FirstOrDefault(y => y.BuyerID == POHeader_Row.BuyerID && y.Company == POHeader_Row.Company);
BpmContext.BpmData[“Character01”] = PurAgent.EMailAddress;
3 Likes

Thank You TobyLai
I’ll try this…