You cannot make any ... until a Transaction has been started

kirkostaskirkostas Member Posts: 127
I am in Sales Order form and I have created a new codeunit which do some calculations.
Both of them have as table source the Sales Header table.
I am sending Sales Order REC (which is the Sales Header table) to the codeunit, I do my calculations and I put the values in some fields in the same table.
When I return to Sales Order form, even if I press Refresh I cannot see my values.
I stopped the code on OnModify trigger of Sales Header table but it never go there. I tried to use LOCKTABLE and MODIFY inside the codeunit but I get the error 'You cannot make any changes to the database until a Transaction has been started'.
I also tried COMMIT but no luck.
Is there a way to modify my fields inside the codeunit and using refresh to see them in the form?
How can I start a transaction?
Why when I do this on a form it works?
kirkostas

Comments

  • David_CoxDavid_Cox Member Posts: 509
    At what point are you passing the Sales Header to the codeunit?
    It may be that you need to save the record before passing it!

    As a guide look for something that does what you want to do, send a sales header and have a modified record returned, so with that in mind, look at the call to the Release Codeunit, and how this works, this sends back the modifed record to the form.

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • kirkostaskirkostas Member Posts: 127
    I am passing Sales Header table while I am on Sales Order form.
    Yes I understand that the problem is that the record is locked by the form
    and I am not be able to modify it.
    How can I save the record before passed it?

    Let me explain what I want to do.
    Sales Order has a sub form Sales Line.
    So I want every time the user enter a new record in Sales Line sub form to run my codeunit which is Sales Header table, do some calculations, pass the values in my new fields, update the table and when got back to Sales Order form to see the modifications.
    kirkostas
  • David_CoxDavid_Cox Member Posts: 509
    Ah the problem is updating the Header from the line table, while the sub form has the focus (Active), could you explain exactly what you are trying to update, is it a running total of the lines on the header, there may be a better way of doing it?

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • diptish.naskardiptish.naskar Member Posts: 360
    Hi,

    When the user is entering the data in the Sales header subform, it is not the sales header table but rather the sales line table. If you want to do some calculation based on the sales line and then update the sales header which ash got some new fields, there are various ways of acheiveing the same. But first we all need to know what exactly are you trying to update.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • kirkostaskirkostas Member Posts: 127
    I just wanted to update the Sales Header table which unfortunately was handled by the form, so finally I solved my problem by entering in Form - OnModifyRecord the EXIT(TRUE); Now the form will update the table and finish the transaction and I am able to LOCKTABLE and MODIFY any field I want.

    Problem SOLVED.
    kirkostas
  • Cem_KaraerCem_Karaer Member Posts: 281
    If you want to make any modification on an argument, you must pass the argument by reference. If you pass it by value, any change you make in your function will not be reflected to the passed variable.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • kirkostaskirkostas Member Posts: 127
    I don't understand what are you trying to tell me.
    You are trying to tell me the EXIT(TRUE) isn't safe enough?
    kirkostas
  • Cem_KaraerCem_Karaer Member Posts: 281
    What I said is a general approach. You can implement whatever you feel easy. If you want to modify a record variable in any function, you must pass it by reference. In that way you do not only pass the values stored in this variable but also the memory address of the variable. Because the function will know the memory address, it will be able change the content of the original variable.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
Sign In or Register to comment.