I have a form which calls a codeunit, using the syntax Codeunit.RUN
That codeunit modifys the Item table. When I run the codeunit, the first time it attempts to modify a record I get the following message :
‘You cannot make any changes in the database until a transaction has been begun’
I really thought I understood about write transactions. What am I doing wrong ? I originally had the code as a function within the form and got the same message. This is V4 sp1 using the native database.
I wonder if this is because my form includes a subform which displays Item records. I was hoping to make a pass through the Item table and set a couple of booleans, which are then used in the filtering of the subform. The sourcetable for my mainform is one of my own making.
What trigger is calling the code? There are a number of triggers that do not allow modifications to the database; if you try to modify the database from one of these triggers you will get an error. In versions 3.x and earlier the error message was “You cannot make any changes in the database from this trigger.” In version 4.x the error message is “You cannot make any changes in the database until a transaction has been started.”
I am afraid that is not possible.
I think it is better to create a function in the subform. The main form calls that function in the “OnAfterGetRecord”.
The function selects the records to be shown, but MARK’s them (using Rec!), then at the end, put a MARKEDONLY(TRUE); and the subform will show you only the marked record. This will work and as an extra:you don’t write to the DB.
Ahh … I didnt realise this message was to do with triggers that dont allow updates to the database. I moved the call from the OnAfterGet Record trigger to a button on the form. Problem solved, thank you.