Can't use the answer from a Code Unit through a Web Service

HenrikDK
Member Posts: 14
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:
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.
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.
0
Comments
-
The error is quite clear, I would say.
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.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Thanks for the answer.
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?
/Henrik0 -
use a temp table job so the validation is an option.
Then after everything is good transfer the records to the real table and post0 -
The problem will be the same in a temp table; I am trying to execute some code that validates values into fields and trying to insert records. To avoid error msg I have put this code in a code unit that is run with IF NOT(CODEUNIT.RUN()) Then and this works great inside NAV. When I try to do this via the web service, then it fails and gives me the error msg. posted in the original post.
Any ideas? Thanks in advance.
/Henrik0 -
The only thing you can do is redesign all, so that you are NOT in a transaction when you do a "IF CODEUNIT.RUN(...) THEN".
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.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
And what is the definition of "a transaction"?
Sorry if it is a stupid question; just need the terminology to be correct
/Henrik0 -
A transaction s a block of changes (Insert/modify/delete) to the DB that must be committed as a whole or not at all.
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.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions