NAV 2017 Web Service Page with an update

sbranin1sbranin1 Member Posts: 8
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

Answers

  • txerifftxeriff Member Posts: 500
    Hi,

    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)....

  • geronimogeronimo Member Posts: 90
    what i usually do when i need to update other tables is expand the webservice with an extension codeunit:

    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
  • sbranin1sbranin1 Member Posts: 8
    Thanks for the responses but I am missing something or being dense. The fields I need to return in the XML are from the Sales Header. The field that I need to update is in another table. I looked at the extension example and I can't figure out how to use it for my purposes.
  • geronimogeronimo Member Posts: 90
    if you follow the link in my original post you can see that there is a function capitalizename

    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)
  • mdPartnerNLmdPartnerNL Member Posts: 802
    then you need 2 pages. 1 for Sales header + 1 for another table. Or use a codeunit.
  • sbranin1sbranin1 Member Posts: 8
    Thanks Geronimo. I tried to do just that and I am still getting the error: A transaction must be started before changes can be made to the database. If I remove the MODIFY from the codeunit, I don't get the error but then the field doesn't get updated.
  • geronimogeronimo Member Posts: 90
    i'll try to have a look into the situation as soon as i find some time to it.
    i'll keep you updated :)
Sign In or Register to comment.