I am trying to build a Pre-Proc BPM on Part.Update that would Raise an Exception when a user checks the Track Serial Number checkbox for a part with 0 quantity on hand. I have been trying to use custom code more often but I am still pretty much a beginner at coding in C#.
The exception message doesn’t get triggered when the BPM is enabled. What Am i doing wrong ?
foreach (var part in ds.Part.Where(o => o.Added() || o.Updated()))
{
// Check if TrackSerialNum changed from false to true
bool trackSerialNumChanged = part.Updated() && part.TrackSerialNum == false && part.TrackSerialNum == true;
// Check if PartWhse.OnHandQty is zero
bool onHandQtyZero = ds.PartWhse.Any(pw => pw.PartNum == part.PartNum && pw.OnHandQty == 0);
if (trackSerialNumChanged && onHandQtyZero)
{
var msg = $"The Stock for this part is equal to zero, please do not check the Track Serial Number option";
throw new Ice.BLException(msg);
}
}
You are getting into the area where you need to compare what the value used to be to what it is being changed to. Only advice I can give is to do a trace and look at the datasets to see if there is a way to identify if the field was changed.
Eric - just curious about the business scenario this addresses. Seems like this would mean you wouldn’t/couldn’t add a new SN-tracked part. And if you already had QOH, how would you assign SNs to the quantity already on hand, as they would not have SNs.