I am trying to make sure the person who picks the part is picking the oldest lot. If they are not picking the oldest lot, I have a raise exception that will stop the transaction and give them the oldest lot. This is an Issue Material Transaction and when they do not pick the oldest lot, the BPM fires twice. I am not sure why this is happening. Not sure if it is in my BPM or if there is a way to stop it in the BPM. Everything in the BPM is below.
First Code Block is to make sure I pull in only parts that are lot tracked:
var pt = ttPartTran.Where(x => x.Added() || x.Updated()).FirstOrDefault();
var part = Db.Part.Where(z => z.Company == pt.Company && z.PartNum == pt.PartNum && z.TrackLots == true).FirstOrDefault();
if(part != null)
lotTracked = true;
Then I have a condition to check if it lot tracked and STK-MTL move.
it seems like i remember having trouble with PartTran… I think that it might first get ADDED and then UPDATED with additional informaiton. Because your BPM is checking for add OR updated, it may be run twice.
Try only looking for ADDED PartTran records.
ALSO… did you know that you can make this section of code more efficient by using the .any statement in the query? .Any() (instead of .FirstOrDefault()) will return a TRUE if it finds the condition. This is more efficient because it doesn’t return any other data, and also stops when it finds the first record that IS true.
Whenever checking for the presents of a record, it is always better to use .any
I have changed the code to look for x.Added(), but when I make that change, the BPM does not fire. It will fire if I use the .Updated(), but fires twice. I have made a change to look for TranQty > 0 as well but it still fires twice.
I think the BPM is working, except when I show message as warning and have the terminate on error checked true, the transaction still goes through. When I have raise exception in the BPM, it throws the error and stops the transaction, but the Application error does not give the user any details about why the error was thrown. example below. How can I change this to show the information the user needs to select the correct lot.