Options

Web Service Insert Order Roll Back

LnZLnZ Member Posts: 37
edited 2010-01-26 in NAV Three Tier
Hi,
I'm inserting an order via Web Services and wolud like to do a complete roll back if there are some errors (eg: a Sales Line with a blocked Item), I don't want to increment the Sales Series Number if the order is not inserted.
Is it possible?
LnZ
P.S.:Sorry for my bad English.

Here is my code:
try
{
  lblError.Text = "";
  //Create Header
  Order SalesOrder = new Order();
  SalesOrderService.Create(ref SalesOrder); //Here it increments the Series Number
  //Update Header
  SalesOrder.Sell_to_Customer_No = "10000";
  SalesOrder.SalesLines = new Sales_Order_Line[2];
  //Create Sales Lines
  for (int idx = 0; idx < 2; idx++)
      SalesOrder.SalesLines[idx] = new Sales_Order_Line();            
  SalesOrderService.Update(ref SalesOrder);
  // Update Sales Line
  Sales_Order_Line line1 = SalesOrder.SalesLines[0];
  line1.Type = Ordini.Type.Item;
  line1.No = "LS-75";
  line1.Quantity = 3;
  Sales_Order_Line line2 = SalesOrder.SalesLines[1];
  //The following article status is blocked
  line2.Type = Ordini.Type.Item;
  line2.No = "LS-100";
  line2.Quantity = 3;
  SalesOrderService.Update(ref SalesOrder); //Here it gives the blocked article Error
}
catch (Exception e)
{
  lblError.Text = e.Message;
}              

Answers

  • Options
    krikikriki Member, Moderator Posts: 9,096
    1) webservice NAV2009 (the original without hotfix) has a bug: the COMMIT command does NOT do a COMMIT!

    2) otherwise : search where the COMMIT is, and do a test:
    IF NOT ISSERVICETIER THEN
      COMMIT;
    
    The problem is: you have to find all COMMIT. And if later on, someone adds a commit,.....
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    ara3nara3n Member Posts: 9,255
    I don't think there is a COMMIT issue in here

    SalesOrderService.Update(ref SalesOrder);
    

    Is one transaction and it is being called twice, hence two transactions.


    These are the options.

    1. Delete the any records created if you get any error.

    2. Write the data into staging table and call a NAV function to create the PO and if errors out to delete the data from staging table.

    3. Create a codeunit with a function and pass XMLport as paramter. I haven't tried this yet.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    LnZLnZ Member Posts: 37
    Thank You ara3n,
    I think that the third option is the most suitable for me.
    LnZ
    ara3n wrote:

    These are the options.

    1. Delete the any records created if you get any error.

    2. Write the data into staging table and call a NAV function to create the PO and if errors out to delete the data from staging table.

    3. Create a codeunit with a function and pass XMLport as paramter. I haven't tried this yet.
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    ara3n wrote:
    2. Write the data into staging table and call a NAV function to create the PO and if errors out to delete the data from staging table.

    This is what I would suggest also. Though I would not delete the data if there is an error, I would add a status field and mark the order as failed, this gives you an audit trail and lets the user check what went wrong, Then once resolved, flush out the old data.
    David Singleton
  • Options
    ara3nara3n Member Posts: 9,255
    Yes, I use that for most integration. It would depend on who the user is on the web and what kind of error you would get.
    For example if they typed their zip code wrong, then the user should get the error and after they fix it resend it from the web.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.