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
0
Comments
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
In fact in SALESORDERCREATION batch i also put code like IF SALESORDERCRATION.RUN THEN;
Regards,
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n