Page 1 of 1

Update Sales Order History Status on an Order just inserted

PostPosted: Fri Feb 01, 2019 7:05 am
by SBarnes
I have some code that inserts an order into Jiwa via the api.

I then need to set it's history status to a value of 2, I believe a Patch request can do this, is this correct?

If the patch request can do this is there a simple way to convert the sales order returned from the original post request into a patch request?

Will ConvertTo mentioned here (http://docs.servicestack.net/auto-mapping) work?

Re: Update Sales Order History Status on an Order just inser

PostPosted: Fri Feb 01, 2019 9:30 am
by SBarnes
Further to this I have written the following function to do the patch

Code: Select all
        private void PatchOrder(JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder salesorderresp)
        {

            using (JsonServiceClient client = new JsonServiceClient(reader.JiwaURL))
            {
                client.ReadWriteTimeout = new TimeSpan(0, reader.Timeout, 0);
                client.Timeout = new TimeSpan(0, reader.Timeout, 0);
                client.Headers.Add("jiwa-stateful", "false");
                try
                {
                    var authResponse = client.Send<ServiceStack.AuthenticateResponse>(new ServiceStack.Authenticate()
                    {
                        provider = "credentials",
                        UserName = reader.JiwaUser,
                        Password = reader.JiwaPassword,
                        RememberMe = true
                    });
                   
                }
                catch (WebServiceException ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ErrorMessage);

                    return;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);

                    return;
                }

                try
                {




                    SalesOrderPATCHRequest salesOrderUpdate = new SalesOrderPATCHRequest();
                    salesOrderUpdate = salesorderresp.ConvertTo<SalesOrderPATCHRequest>();
                    salesOrderUpdate.Histories[0].Status = JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderHistory.SalesOrderHistoryStatuses.e_SalesOrderHistoryStatusReadyForPicking;
                   
                    salesorderresp = client.Patch<JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder>(salesOrderUpdate);

                }
                catch (WebServiceException ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ErrorMessage);
                    //order.MoveFile(order.FileName, reader.DesktopPath + "MCAOrders\\Error");
                    return;
                }
                LogoutGetRequest logout = new LogoutGetRequest();
                LogoutGetResponse lresp = client.Get<LogoutGetResponse>(logout);

            }
        }


which get an exception of The request was aborted: The connection was closed unexpectedly.

when I put i launch the debugger inside the web api here is the stack trace

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException
  HResult=0x80131500
  Message=Carrier with a RecID of  not found.
  Source=JiwaSales
  StackTrace:
   at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Carrier.ReadCarrier(String SeedValue, Boolean SeedIsID)
   at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Carrier.DTO_Deserialise(SalesOrderCarrier Carrier)
   at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory.DTO_Deserialise(SalesOrderHistory History)
   at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistoryCollection.DTO_Deserialise(List`1 Histories)
   at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.DTO_Deserialise(SalesOrder SalesOrder)
   at JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrderServices.Patch(SalesOrderPATCHRequest request) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.0\SYSTEM\EC2AMAZ-OR5EG17\CASSONSDEV\Plugins\Admin\Compile\REST API\REST API.cs:line 17850
   at ServiceStack.Host.ServiceRunner`1.<ExecuteAsync>d__13.MoveNext()


How can I get around this error?

Re: Update Sales Order History Status on an Order just inser  Topic is solved

PostPosted: Fri Feb 01, 2019 10:27 am
by SBarnes
I've gotten round the problem by the following on the the sales order post

Code: Select all
   salesorder.Histories.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderHistory() { Status = JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderHistory.SalesOrderHistoryStatuses.e_SalesOrderHistoryStatusReadyForPicking});




but how can you get around the patch issue when there are no carriers?

Re: Update Sales Order History Status on an Order just inser

PostPosted: Fri Feb 01, 2019 3:41 pm
by Mike.Sheen
SBarnes wrote:but how can you get around the patch issue when there are no carriers?


Set the carrier RecID and carrier Name to null before converting to a patch request. If after that converting it to a patch request still shows the carrier RecID as blank, then set the carrier RecID and carrier Name in the patch request to null before sending it.

I don't think we should be sending a response back with a blank carrier RecID or Name if there is none selected - it should be null and therefore will be excluded from the response DTO completely - either that or when deserialising we should treat a blank carrier RecID the same as null.

Logged as DEV-7141

Re: Update Sales Order History Status on an Order just inser

PostPosted: Fri Feb 01, 2019 3:46 pm
by SBarnes
Thanks Mike,

I think you mean CarrierID to null and not RecID but I get the idea.