Erp.SalesOrder.ChangePartNumMaster Pre-Processing Throw an Exception

I have a check in place that keeps certain parts from being added to an order. I’m using the ChangePartNumMaster Pre-Processing method to throw an exception if it meets the condition.

However, when exception dialog is closed on Sales Order Entry Form, the line detail part number is set to blank. That’s okay if it’s a new line but I’d like to find a way to reset it to the previous value if the user is changing the part number on an existing line.

I have tried refreshing the data before throwing the exception using:

var ds = svc.GetByID(orderNum);
this.dsHolder.Attach(ds);

with no luck.

Is using ChangePartNumMaster the right approach to keep parts from being added?

I can certainly move the logic to a data directive or the update method but I’d like to give the user immediate feedback instead of waiting until they save.

I found that I simply needed two BPMs… one at ChangePartNumMaster that does not throw an exception, but instead, simply shows a message, and another on the sales order Method that throws a hard error if they dont fix it.

If I take your approach, would I then move the ChangePartNumMaster logic from Pre-Processing to Post? Or it doesn’t matter as long as the message is not an exception?

Hmmm… maybe try moving it to Post before trying anything else… maybe that is the problem? (sometimes BPMs require some Experiments to find out what works).

I’ll give it a shot but I guess in my experiences, is that throwing the exception in Post doesn’t really do anything because it’s already committed at that point. We’ll see…

After some more trial and error, still using Pre-Processing. I found that apparently there are differences in the widgets for showing messages that the Sales Order form handles differently.

If I used the “Raise Exception” with a severity of “Error”, it would clear the part number in the form.

If I used “Show Message” with a severity of “Error”, it would keep the proposed part number and not save. Which was a step forward.

Then if I set the partNum argument back to the previous value, then it would show up in the form as the previous value. Which is the behavior I was trying to reach.

So to recap:

  1. If you don’t want the part number cleared out in the form after a thrown “exception” then use the “Show Message” widget.

  2. If you want the part number to return to the previous value in the form, set the partNum argument back to the previous value. Which in this case is partNum = ttOrderDtlRow.PartNum; of the changed row, prior to the “Show Message” widget.