Hello,
I’m on 10.1.400.23. I have been building an emailer on a Standard Data Directive on RcvHead. When a certain BuyerID makes a PO, they only make ones that are Buy-To-Order. I’m using the email “template” Haso Keric has posted before.
I’m not great at C#, but I’m trying to tease my way through this.
Here where I’m making choices based on BuyerID, and I need help on how to approach the connection of BuyerID to Salesperson email. see my commented out text:
switch (POHeader_Row.Buyerid)
{
case "2001":
BuyEmail = "XXX@co.com";
break;
case "1001":
BuyEmail = "XXX@co.com";
break;
case "2701":
BuyEmail = "XXX@co.com";
break;
case "2003":
case "1003":
case "1703":
BuyEmail = "XXX@co.com";
break;
case "2002":
case "1002":
case "3702":
BuyEmail = "sales-email@co.com"; // link POHeader to to PO Detail to get Sales Order for BTO lines. Use that SO # to get Salesperson ID. Use that ID to get Salesperson emailaddress
break;
default:
BuyEmail = "XXX@co.com";
break;
}
// Send Email
It looks like maybe you are trying to figure out how retrieve and link different tables? In a directive LINQ is where it’s at.I’m pretty horrible at LINQ so someone like Aaron will be much more useful but as a general example or pulling and linking:
var Result = from D in Db.Device //this just gets results from the temp table parttrans which is the result of this BPM
join P in Db.SysPrinter
on new { D.Company, D.PrinterID } //link these
equals new { P.Company, P.PrinterID } // to these
where D.WorkStationID == Session.WorkstationID
select P.NetworkPath;
prntr = Result.FirstOrDefault();
}
I put on my big boy pants and dug in. I’m trying to get a Salesperson email address with my starting point as a BTO receipt. The BuyerID that is used for this will always be making this Buy to Order type of PO.
Below in my code snippet, I’ve established that I can read the POHeader.BuyerID. I’ve tested it. I get a BuyerID that corresponds to the specific POHeader. It equals 3702.
My current issue is the next jump.Within my Switch / Case I’m trying to get the BTOOrderNum. In order to get my BPM to save I have to comment out " //&& pd.PONUM == POHeader_Row.PONum" as you see below. When I do that My BTOOrderNum = 0 because that is what the lowest numbered PODetail record has for that column. It is NOT the PO I want.
If I remove the ‘//’ I get this error when I try to save:
“Error CS1061: ‘AnonymousType#1’ does not contain a definition for ‘PONum’ and no extension method ‘PONum’ accepting a first argument of type ‘AnonymousType#1’ could be found (are you missing a using directive or an assembly reference?) [PostTran.DictionalEmail.cs(238,67)]”
Is POHeader_Row no longer valid once I’ve crossed into the Switch / Case? Because I’m counting on the POHeader_Row.PONum to match to give me the correct PODetail record to feed my BTOOrdernum. Is this thinking wrong? Or do I have some other syntax wrong?
var POHeader_Row =
(from B in Db.POHeader.With(LockHint.NoLock)
where
B.Company == ttRcvHead_Row.Company &&
B.PONum == ttRcvHead_Row.PONum
select new { B.BuyerID }
).FirstOrDefault();
switch (POHeader_Row.BuyerID)
{
case "3702":
var POD_Row =
(from pd in Db.PODetail.With(LockHint.NoLock)
where pd.Company == CompanyID //&& pd.PONUM == POHeader_Row.PONum
select new { pd.BTOOrderNum }).FirstOrDefault();
var POHeader_Row =
(from B in Db.POHeader.With(LockHint.NoLock)
where
B.Company == ttRcvHead_Row.Company &&
B.PONum == ttRcvHead_Row.PONum
select new { B.BuyerID }
).FirstOrDefault();
**PONum** = ttRcvHead_Row.PONum;
switch (POHeader_Row.BuyerID)
{
case "3702":
var POD_Row =
(from pd in Db.PODetail.With(LockHint.NoLock)
where pd.Company == CompanyID && pd.PONUM == **PONum**
select new { pd.BTOOrderNum }).FirstOrDefault();