Hey,
I am making a Time Registration Solution, but I receive an error when I try to use it through a web service. The code is placed in the insert/modify trigger and is run to check if the line can be inserted in a Job Journal Line. The actual code that inserts the line is placed in a Code Unit, so on-screen error messages can be avoided.
The error I reseive:
Codeunit.Run is allowed in write transactions only if the return value is not used. For example, 'OK := Codeunit.Run()' is not allowed.
The code lines in the table:
IF NOT(CODEUNIT.RUN(CODEUNIT::"TR Test Insert Line",pTimeRegistration)) THEN BEGIN
pErrText := lText003;
EXIT(pErrText<> '');
END;
The code that tries to validate and insert the line in the Job Journal Line, is in the
TR Test Insert Line-Code Unit.
Do you have an idea how to solve it or a possible work around?
Hope you can help.
Comments
You are in a transaction and want to do a "IF CODEUNIT.RUN(..) THEN" which is not allowed.
Solutions are 2:
-Or you do a "CODEUNIT.RUN(..);" without the IF THEN.
-Or you make sure you are NOT in a transaction. This last you can do by putting a COMMIT just before the "IF CODEUNIT.RUN". BUT BEWARE: I don't know what you have done before that statement so you are in a transaction. By putting a COMMIT there, you can endanger integrity of your data in case something goes wrong after THE COMMIT but before the end of the complete job.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I need an answer from the Code Unit, because I am trying out if I can post a line in the Job Jounal Line table.
The reason why I moved it to a Code Unit, is because I get an onscreen error and stop of code-run, when I do it inside the table it self.
Do you have an idea how I can check if the fields in Job Journal Line can be validated and afterwards inserted; other then using Commit?
/Henrik
Then after everything is good transfer the records to the real table and post
|To-Increase|
Any ideas? Thanks in advance.
/Henrik
I am afraid there is no other option.
While I was writing the last phrase, I found another option:
Instead of calling the codeunit like that, do another webservice call from NAV just to try your test. Maybe this works.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Sorry if it is a stupid question; just need the terminology to be correct
/Henrik
NAV starts a transaction automatically at the first change to the DB until a COMMIT is run or until the control is given back to the user.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!