Page 1 of 1

Retrieving Errors/Warnings

Posted: Thu Jul 11, 2019 10:37 am
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.

Re: Retrieving Errors/Warnings

Posted: Thu Jul 11, 2019 2:48 pm
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().

Re: Retrieving Errors/Warnings

Posted: Thu Jul 11, 2019 3:28 pm
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.