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.
Retrieving Errors/Warnings
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Retrieving Errors/Warnings
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.
And below is where the order save is attempted. Instead, the order is cancelled by my handler and the errors and warnings are available.
The definition for IOrderMessage objects is in the SDK. And allows you to retrieve all the original information written by AddError() and AddWarning().
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;
}
Code: Select all
os.OrderSaving += Os_OrderSaving;
try
{
os.ApplyChanges(order);
}
catch (OperationCanceledException ex)
{
IEnumerable<IOrderMessage> messages = order.GetMessages();
}
Bob Richards, Senior Software Developer, SoftPro
Re: Retrieving Errors/Warnings
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.