Error Saving Order

Discussions related to custom development with Select.
Post Reply
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Error Saving Order

Post by PeterKelly »

I sometimes get an error saving an order thru the API:

System.OperationCanceledException: The order has unresolved errors. Any outstanding errors must be resolved before the order can be saved.

Is there a way to retrieve the reason that would normally show in the UI? Eg. "Transaction type should be purchase if a seller or sales price is entered"

Thanks,
Peter
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Error Saving Order

Post by john.morton »

There are messages available on the IOrder. You can examine their Level to see their severity, and act accordingly:

Code: Select all

            using (IOrder order = OrderStore.NewOrder(spec))
            {
                try
                {
                    // Manipulate your new order here
                    foreach (IOrderMessage message in order.GetMessages())
                    {
                        MessageBox.Show(message.Text);
                    }

                    if (!order.GetMessages().Any(m => m.Level == OrderMessageLevel.Error))
                    {
                        OrderStore.ApplyChanges(order);
                    }
                }
                finally
                {
                    OrderStore.CloseOrder(order);
                    MessageBox.Show(string.Format("We successfully created order"));
                    
                }
            }
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Re: Error Saving Order

Post by PeterKelly »

Thanks!
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Re: Error Saving Order

Post by PeterKelly »

I get an error: 'Order' does not contain a definition for 'GetMessages'

But the SDK version I have, which is a bit old(3.0.10820.130), shows it as a valid method on IOrder. I'll have to get the latest version and verify.
mmregan
Posts: 17
Joined: Tue Mar 09, 2010 2:27 pm

Re: Error Saving Order

Post by mmregan »

You need to call GetMessages on the strongly typed IOrder reference, not on your dynamic order reference.
Post Reply