Update Sales Order History Status on an Order just inserted  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Update Sales Order History Status on an Order just inserted

Postby SBarnes » Fri Feb 01, 2019 7:05 am

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

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

Postby SBarnes » Fri Feb 01, 2019 9:30 am

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

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

Postby SBarnes » Fri Feb 01, 2019 10:27 am

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

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

Postby Mike.Sheen » Fri Feb 01, 2019 3:41 pm

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
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

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

Postby SBarnes » Fri Feb 01, 2019 3:46 pm

Thanks Mike,

I think you mean CarrierID to null and not RecID but I get the idea.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 2 guests

cron