Retrieving Errors/Warnings

Discussions related to custom development with Select.
Post Reply
ShawnALaw
Posts: 6
Joined: Wed Jul 10, 2019 1:05 pm

Retrieving Errors/Warnings

Post by ShawnALaw »

So I'm working on an internal API for softpro that was started by a different person a few months ago.
They have a service sitting somewhere with custom validations using OrderSavingEventArgs.AddError
API-side, when I try to save an order with OrderStore.ApplyChanges(Iorder), if the validation fails, it tells me that it failed, but I can't seem to get a hold of the errors themselves. I would really like to get the text out of them so I can return it to the API caller instead of making them guess at the error since they have like 200 rules.
I suppose I could pull their service into the API, and build a system to copy them or something, but it seems like there should be a simple solution to getting a hold of them that I just can not find. Thanks for the help.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Retrieving Errors/Warnings

Post by BobRichards »

Yes, you can get any messages that are in the queue. In this example in the IOrderStore.OrderSaving() handler, I added several items and set the appropriate flags to cancel the save.

Code: Select all

private void Os_OrderSaving(object sender, OrderSavingEventArgs e)
{
    e.AddError(e.Order, "IsRush", "IsRush error");
    e.AddError(e.Order, "Project", "Project error");
    e.AddWarning(e.Order, "SettlementDate", "SettlementDate warning");
    e.Reason = "the reason";
    e.Cancel = true;
}
And below is where the order save is attempted. Instead, the order is cancelled by my handler and the errors and warnings are available.

Code: Select all

os.OrderSaving += Os_OrderSaving;
try
{
    os.ApplyChanges(order);
}
catch (OperationCanceledException ex)
{
    IEnumerable<IOrderMessage> messages = order.GetMessages();
}
The definition for IOrderMessage objects is in the SDK. And allows you to retrieve all the original information written by AddError() and AddWarning().
Bob Richards, Senior Software Developer, SoftPro
ShawnALaw
Posts: 6
Joined: Wed Jul 10, 2019 1:05 pm

Re: Retrieving Errors/Warnings

Post by ShawnALaw »

Excellent! I could not for the life of me find what they were called. I'm not sure how I missed that now, though. Thank you very much.
Post Reply