The unknown power of Messages

Hi, I have a strange case: When “Allow Invoice Discount” is set on the Sales Line, I run a Codeunit, which calculates the Invoice Discount. Anyway, if i write something like in the Codeunit: Message(’’); or’’); Window.close; The Invoice Discount is not the same as when i don’t write theese lines in then Codeunit. Anyone can explain me why[?]

Could you explain the difference?

The difference is the following: The amount in the field “Inv. Discount Amount” is not the same. Also if i start the Code Coverage i see that about 30 lines are executed, when i have the message in the Codeunit, which are not executed, when i delete “message(‘xyz’);” from the codeunit.

Hmmmm… I don’t see any reason why a message would change the value of “Inv. Discount Amount”! Maybe this doesn’t answer directly to your question, but when you trying debuging with messages, I suggest the use of CONFIRM. CONFIRM will stop the execution of your code and wait for the user selection. At the opposite, MESSAGE will send a Windows message in a queue, so a lot of lines of codes can be executed after the message before you see it on your screen. Are you working with the standard Invoice in Navision, or does the area has been customized?

Hello Mr. Godbout, the area has been customized. Maybe You can tell me, why the Inv. Discount Amount can be calculated correctly, when i modify the quantity (what causes a run of the same codeunit like when i set “Allow Invoice Disc”) and press the [TAB] button, but when I press the [Up] or [Down] button, the Inv. Discount Amount is calculated differently. Thx for every Minute You think about.

Does it work correctly when you are using debugger? With and without MESSAGES or Windows?

You are speaking of the value of “Inv. Discount Amount” in the Invoice statitics (F9), right? If so, it’s normal that you don’t have the same numbers, because a record is modified when it looses the focus. So, when you press up/down, the modification will be done in the database, but if you press tab (to go to the next field), you are still modifying the actual record and your changes are not updated when you press F9.

Dear Mr. Bacher When i use the Debugger it doesn’t change anything. That means: When i show the message (or window) it works, when i don’t show it, it doesn’t work thx

Dear Mr. Godbout, this seems to be quite logic, but the problem occures, when i press UP or DOWN… when i Press TAB, the Inv. Discount Amount is calculated correctly. Thx


Originally posted by touny
Dear Mr. Godbout, this seems to be quite logic, but the problem occures, when i press UP or DOWN… when i Press TAB, the Inv. Discount Amount is calculated correctly. Thx

Hmmm… That’s interesting! I would suggest first of all to compare your customized database with a Navision standard database. Then, you’ll see if the error comes from your customizations. After that, as Stefan suggested, I would use the debugger or any techique using “breakpoints” to see where the error comes from. When you have found the source of the error, you will be able to correct it.

Funnily enough, I’ve just been exploring a similar situation with a database that the end-user has customised (2.60). The background isn’t important but basically, they input a value in field 1 which then calls the OnValidate of field 2. In the code for field 2, it has a confirm that the user has to respond to if the value is beyond a certain tolerance. With the confirm in place, when you enter the value in field 1 and press , the field reverts to its original value but if you press the up/down arrow after entering the value in field 1, it retains the input. The debugger doesn’t help because if you use it and inspect the records as you go, everything works OK! Similarly, without the confirm, using or the arrows works as expected. What I finally established, with message boxes in the OnAfterValidate trigger of field 1 (on the form) and OnAfterGetRecord trigger is that the field is correctly updated after the validate, whether the confirm message is there or not, but the record is not being modified so when the OnAfterGetRecord is triggered, it gets the unmodified record with the original values. A CurrForm.UPDATE(TRUE) on the OnAfterValidate trigger works. Alternatively, setting the UpdateOnActivate property aso works. All in all, a very bizarre situation. Cheers John

This seems to be a bug in the navision client (>v3.60 SP0) if you put a CurrForm.SAVERECORD in the OnAfterValidate of the field in the form where it is entered it works. This has NOT been the case in a client of Version 3.60. i am using 3.70 to develop and there this error happens. also SP2 3.60 have this bug i guess, since 2min after installing SP2, the customer called us up and told us that story, which never happended to them before.

This “rollback after message”-error is a known issue and is solved in 3.70 hotfix 10 and 3.60 hotfix 28. Make sure to use the latest executables.