Hello. We have a Standard Data Directive on OrderHed that uses Custom Code to access the Customer table for the simple purposes of sending an email to the salesperson.
It is seemingly very simple code, but I don’t know enough about the syntax to modify it in the way I need. Here is the code:
var MyCustomerRec = (from row in ttOrderHed
join MyCustomerRecRow in Db.Customer
on row.CustNum equals MyCustomerRecRow.CustNum
select MyCustomerRecRow).FirstOrDefault();
var MyUserRec = (from row in ttOrderHed
join MyUserRecRow in Db.UserFile
on row.EntryPerson equals MyUserRecRow.DcdUserID
select MyUserRecRow).FirstOrDefault();
var MyTermsRec = (from row in ttOrderHed
join MyTermsRecRow in Db.Terms
on row.TermsCode equals MyTermsRecRow.TermsCode
select MyTermsRecRow).FirstOrDefault();
if(MyCustomerRec != null)
{
callContextBpmData.Character01 = MyCustomerRec.Name;
callContextBpmData.Character02 = MyUserRec.EMailAddress;
callContextBpmData.Character04 = MyUserRec.Name;
callContextBpmData.Character03 = MyTermsRec.Description;
}
What I need to add is a way to specify the Company of the Customer record. We are multi-company so the same CustNum can exist in both Companies. This sometimes results in the wrong Customer Name being pulled. I’ve tried:
var MyCustomerRec = (from row in ttOrderHed
join MyCustomerRecRow in Db.Customer
on row.CustNum equals MyCustomerRecRow.CustNum
and row.Company equals MyCustomerRecRow.Company
select MyCustomerRecRow).FirstOrDefault();
which threw a lot of errors, and
var MyCustomerRec = (from row in ttOrderHed
join MyCustomerRecRow in Db.Customer
on row.CustNum equals MyCustomerRecRow.CustNum
where MyCustomerRecRow.Company = '[COMPANY]'
select MyCustomerRecRow).FirstOrDefault();
which only threw the error “Too many characters in character literal” so I’m hoping that one is closer to correct?
Any guidance on how to proceed would be much appreciated. Thank you in advance.