I am attempting to store all ShipToRows in a post-proc method directive for SalesOrder.ChangeCustomer. This isn’t my end game, but it’s a means to the end I seek.
When the ChangeCustomer method fires, I want to query all ShipTos via linq that match the CustNum of the current context. Currently, I’m fetching just the first record off of the shipTos variable for debugging purposes. When I traced, I saw that the value I want is in the SalesOrderDataSet, which I’ve tried to access using ds.OrderHed["CustNum"]
I’m experiencing an issue where no matter what I do, I cannot convert the CustNum from the ds to an Int. I’m guessing this is because I’m doing something wrong and I’m not getting a value that I can convert when I reference ds.OrderHed["CustNum"].
Attached is my code:
int ipCustNum = Int32.Parse(ds.OrderHed["CustNum"]);
var shipTos = (from shipto_row in Db.ShipTo.With(LockHint.NoLock)
where shipto_row.CustNum == ipCustNum
select shipto_row).FirstOrDefault();
if (shipTos != null) {
return true;
}
return false;
The error I receive is: Argument 1: cannot convert from 'string' to 'int'
I am going to assume you are in some kind of Order BPM so yes you can use ds.TableName or ttTableName (alias).
I think you are missing a
var OrderHedRow = ttOrderHed.FirstOrDefault();
Then you could use
OrderHedRow.CustNum
You could even expiriment with JOINs, an example Code
// Initialize Vars
string existingPO = string.Empty;
var shipDtlRows =
from tsd in ttShipDtl
where tsd.Added() || tsd.Updated()
select tsd;
foreach (var ttShipDtlRow in shipDtlRows)
{
existingPO =
(from sd in Db.ShipDtl
join oh in Db.OrderHed.With(LockHint.NoLock)
on new { sd.Company, sd.OrderNum } equals new { oh.Company, oh.OrderNum }
join c in Db.Customer.With(LockHint.NoLock)
on new { oh.Company, oh.CustNum, CheckBox01 = true } equals new { c.Company, c.CustNum, c.CheckBox01 }
where
sd.Company == ttShipDtlRow.Company &&
sd.PackNum == ttShipDtlRow.PackNum &&
sd.OrderNum != ttShipDtlRow.OrderNum
select oh.PONum).DefaultIfEmpty("").First();
if (existingPO != string.Empty)
{
// What we are processing now, does it match our discovery
bool doesNotMatch =
(from oh in Db.OrderHed.With(LockHint.NoLock)
where oh.Company == ttShipDtlRow.Company && oh.OrderNum == ttShipDtlRow.OrderNum && oh.PONum != existingPO
select oh).Any();
if (doesNotMatch)
{
throw new Ice.BLException("Current Lines PO Number does not match previous Lines PO Number");
}
}
}
Oh Haso is right, you cant do this above. Perhaps you only want to look at the first record? First(). But you’ll need to access a row before you try to pull a field.
@hkeric.wci@Chris_Conn thank you both for taking the time to shed some light on best practices with the dataset. I’m going to take a crack at the suggestion and will followup on how I make out.