WEB Service Transaction Role Back.

NavIndiaNavIndia Member Posts: 36
edited 2009-05-26 in NAV Three Tier
I have a strange problem in doing transactions through NAV 2009 Web Service.

1) I pushed XML Documents into Navision through NAV 2009 Web Service.

2) Once the XML document hits Nav, a codeunit will parse the XML Document and then insert data into a table (lets say XMLBuffer Table), in the same codeunit I have written a COMMIT after data inserted into the XMLBuffer table (So that whatever code is executed after this “COMMIT” shouldn’t roleback the insertion of data in XMLBuffer table).

3) After commit statement I have called another codeunit that will create a Sales Order based on the data inserted in XMLBuffer table.

4) Desired Result: During the process of creating Sales Order if any error comes, then the sales order creation process should be rolled-back (till the last commit) and a error log to be created in Nav. Although the data inserted in XMLBuffer table shouldn’t rollback (as COMMIT was written after that).

5) Problem: Now the problem is that if an error comes in the sales order creation then nothing happened in Navision and no data inserted in any table despite using explicit COMMIT after inserting the data into the Table and before calling sales order creation process.

Just for Information: Rather than pushing XML through NAV 2009 Web Service, if I provide the physical path to the XML file and then run the same process than it will insert data in XMLBuffer table and if any error comes in sales order creation process, than it creates a error log else creates a sales order successfully.

As per my assumption, I think when calling from Web Service, it is taking whole process as a single transaction and if any error comes (even after using proper error handler like IF CODEUNIT.RUN THEN) it rolles back fully.
Can you suggest what can be done so that system treats it as 2 processes, called one after other, first process parses the XML and inserts into table and second creates sales order using the inserted data. If error comes in 2nd process, first one doesn’t Role Back.
Code is like this

Codeunit
{
Parse XML …..
Insert into XMLBuffer ….
COMMIT;
If SALESORDERCODEUNIT.RUN(XMLBuffer) then;
}


Regards

Comments

  • ara3nara3n Member Posts: 9,256
    COMMIT are ignored by web service.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    If you want to process them as two separate transaction. Create two functions. Call the first function to insert the xml file. Call the second function to post the transaction.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • NavIndiaNavIndia Member Posts: 36
    Hi Rashed,

    Thanx for reply,

    Actually I also tried with two separate Codeunits like one codeunit for XML importing and another codeunit to process the sales order creation and publish both Codeunits in WEB SERVICE Table. Now the problem is that I can’t ask client to use two separate URL for execute both Codeunits, instead of doing this I create one more webservice as a abstract layer and ask client to use that URL in their reference.

    And in my Abstract layer I set web reference to both my NAV Codeunits. And in a function ProcessRequest (in abstract layer) i put code like this

    ProcessRequest //Function in my Abstract Layer
    Try
    {
    Call ImportXML Webservice(request xml, response xml )
    }
    Catch
    {
    Exception show if any;
    }
    Finally
    {
    Call SALESORDERCODEUNIT();
    }

    But its still not working.


    Thanx
    Regards
  • ara3nara3n Member Posts: 9,256
    what is not working? You get an exception when calling SALESORDERCODEUNIT and this causes the roleback of ImportXML ?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • NavIndiaNavIndia Member Posts: 36
    Yes, when I call the web service n push the xml then it won't segregate it into two processes. If any error comes in SALESORDERCREATION batch then the whole transaction role backed (including xml importing process).

    In fact in SALESORDERCREATION batch i also put code like IF SALESORDERCRATION.RUN THEN;


    Regards,
  • ara3nara3n Member Posts: 9,256
    can you paste your navision code for the two functions?
    Ahmed Rashed Amini
    Independent Consultant/Developer


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