AddBLException causes packing slip to supposedly not be found

I’ve got some custom code in Erp.CustShip.GetByID that is supposed to check for some conditions to be true, and if so, display a message that shipping is not allowed and prevent shipping from occurring.

My understanding is that to throw the actual exception, I need to call CallContext.Current.ExceptionManager.AddBLException() with a string containing the error message. If I’m in Customer Shipment Entry with the test record already loaded and hit refresh, the exception comes up - but the record is still displayed, meaning that shipping is still possible. This isn’t a problem as this is just for testing and in production the record wouldn’t be up in the first place. It does show the BPM is otherwise functioning as expected and proves out the logic.

But if I clear the record and try to re-enter the packing slip number, it says “Record not found. Add new?” I assume the exception is somehow interfering and causing this, but I don’t even see my exception message!

I’ve tried this using both a pre-processing and post-processing method, but both have the same behavior.

What’s your code?

int hardstop_reasons = 0;
/* logic to determine whether or not to throw exception omitted here... */
if (hardstop_reasons > 0) {
  CallContext.Current.ExceptionManager.AddBLException("Hard Stop on Order");
}

Call context can be fussy to work with. If you move your exception to an exception block in lieu of code, does it behave the same?

I haven’t tried that… presumably I would have to pass status out of the custom code block somehow and then test that in a conditional?

If you create local bpm variables then you can set them in either setters or in code, so whatever works best.

I get the same behavior if I raise the exception using the “Raise Exception” widget.

(Annoyingly, I also don’t get any informational messages that are supposed to be displayed in the custom code block before the exception - it’s like an exception retroactively cancels such messages so they don’t pop up. Although, this behavior seems to occur whether the exception was in the custom code block or via a widget.)

Well shoot. Sometimes throwing exceptions can cause weird behavior especially if it’s server side and the client side isn’t totally in sync with that

I’m wondering if this business object just isn’t conducive to being excepted here… but I’m not sure where else to put a hard stop to prevent shipping.

Or perhaps the method you’re targeting might need to change