Options

roll back and commit Transactions

marvindmarvind Member Posts: 25
edited 2009-12-09 in NAV Three Tier
I have a strange problem in doing transactions through NAV 2009 Web Service.
I pushed web service for sales order in Navision Once it published , a codeunit will parse the XML Document and then insert data into a table , in the same codeunit I have written a COMMIT after data inserted into the table (So that whatever code is executed after this “COMMIT” shouldn’t roleback the insertion of data in table).After commit statement I have called another codeunit that will create a Sales Order based on the data inserted in table.

During this 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 table shouldn’t rollback (as COMMIT was written after that).

Now the problem is 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.

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.

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.

Comments

  • Options
    matteo_montanarimatteo_montanari Member Posts: 189
    marvind wrote:
    I have a strange problem in doing transactions through NAV 2009 Web Service.
    I pushed web service for sales order in Navision Once it published , a codeunit will parse the XML Document and then insert data into a table , in the same codeunit I have written a COMMIT after data inserted into the table (So that whatever code is executed after this “COMMIT” shouldn’t roleback the insertion of data in table).After commit statement I have called another codeunit that will create a Sales Order based on the data inserted in table.

    During this 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 table shouldn’t rollback (as COMMIT was written after that).

    Now the problem is 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.

    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.

    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.

    Hi

    It's a know bug of Nav WebService:

    Transactions are not saved in the Microsoft Dynamics NAV 2009 database when you execute the transactions by using Web services (KB973416).

    There is a downlodable Hotfix for this. Require a valid Login.
    Nav2009 SP1 should be ok.

    Bye

    Matteo
    Reno Sistemi Navision Developer
  • Options
    ara3nara3n Member Posts: 9,255
    Actually the issue here is COMMIT.
    Webservices ignore all the commits.

    I would structure your code with if CODEUNIT.RUN wrap the error.

    Or another option is to have two webservice function. The first one insert the record. The second tries to creates the Order.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    matteo_montanarimatteo_montanari Member Posts: 189
    ara3n wrote:
    Actually the issue here is COMMIT.
    Webservices ignore all the commits.

    I would structure your code with if CODEUNIT.RUN wrap the error.

    Or another option is to have two webservice function. The first one insert the record. The second tries to creates the Order.

    hi ara3n,

    On KB973416, Microsoft resolved this Commit issue.. change the architecture for a resolved bug i think is a bit invasive... (imho)...

    Matteo
    Reno Sistemi Navision Developer
  • Options
    ara3nara3n Member Posts: 9,255
    I thought that was a good feature. Is it removed in sp1?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    That's odd, I also remember the same as Rashed, that this was a deliberate feature, so that the developer outside of Navision could have better control of and knowledge of the status of data transacted to Navision. i.e. break the steps into definable units at the web level.

    To me it made good sense, since it is complex to teach a web developer the issues with Navision commits, since they would need to debug lots of Navision code to find out where the commits were and why. This way the web developer can work in a way they are used to.
    David Singleton
  • Options
    pdjpdj Member Posts: 643
    So has the issued been been "solved" by respecting all directs and in-directs COMMIT in code, or how has it been solved?
    I like the way the NAV5 Mobile solution handles it. It simply marks a record as inconsistant, so it fails if it encounters any commits. Then developers could simply disable this commit protection for the selected services, but as a default it should prevent commits. If it instead disabled the commits function, it could be fatal when having code that integrates to other systems via i.e. automations.
    Regards
    Peter
  • Options
    krikikriki Member, Moderator Posts: 9,096
    [Topic moved from 'NAV/Navision' forum to 'NAV 2009' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.