I am trying to expose a web service from NAV 2017 using a Page. This web service needs to return a couple fields from the Sales Header and a couple pieces of calculated data. I created a couple of global variables for the calculated data and added them to the page. I put the code to do the calculation in the OnAfterGetRecord trigger of the Page. If I call the web service with a Read I get back what I would expect. So far so good. Problem is that I also need to update another table with some of the info that I used in the calculation and when I do a MODIFY on that table I get this error: A transaction must be started before changes can be made to the database.
I tried calling the web service using Update and didn't get back the fields I need. I know there must be a way to do this and have searched far and wide but I can't find a working solution. Any ideas would be appreciated.
-Steve
0
Answers
Im not expert on this but... If you want to return data, try exposing a codeunit and create a function like : storemychanges(document no.,parameter2)....
https://msdn.microsoft.com/en-us/library/dd338962(v=nav.90).aspx
and then i write a function for what needs to be done in the codeunit
http://www.kauffmann.nl/2016/10/24/web-services-example-7-call-nav-odata-web-services-part-1/
http://www.kauffmann.nl/2016/12/07/web-services-example-7-call-nav-odata-web-services-part-2/
that is like the function you need.
so for example if you need to update for example a field on a related table you can try the following:
make a function updateextrafield
parameters of this function are:
Sales Header (needed as we extend the page based on sales header)
Text variable (assuming we need to update a text field on the other table)
write the code in nav in this function to get the record and update the field
i hope it makes it a bit clearer (haven't tested this as i have no version at hand at the moment)
i'll keep you updated