In this topic you will learn how to debug the code and identify the codeunits that generate an error.
Debugging the Code
To debug the code
Log on to the database as TestUser and open the General Journal window.
In the Batch Name field, select CASH and enter the information that you want to post. Remember to select ADM in the Department Code field. Do not post the entry yet.
Click Tools, click Debugger, and then click Breakpoint on Triggers to clear the check mark from this option. The debugger will only stop when the code encounters an error.
Click Tools, click Debugger, and then click Active to activate the Debugger.
In the General Journal window, click Posting, and then click Post.
The application runs slower now because the Debugger is running in the background.
After a while the Debugger opens and shows you where it encountered the first error.
In the Debugger window you can see that the first error occurred in codeunit 13, Gen. Jnl.-Post Batch when the code tried to read the last record, FINDLAST in the G/L Entry table.
To solve this, you must give codeunit 13 permission to read all the records in the G/L Entry table.
Giving Permission to the Codeunit
To give permission to the codeunit
In the Object Designer, open codeunit 13, Gen. Jnl.-Post Batch, and open the Properties window.
In the Value field of the Permissions property, click the AssistButton to open the Permissions window for the codeunit.
Add the G/L Entry table to the list and ensure that the codeunit only has read permission to this table.
Click OK to commit the changes that you have made in this window.
Close, save, and compile the codeunit.
You do not need to synchronize the security system after altering the properties of the codeunit as it is not part of the permission system.
Now log on to the database as TestUser, activate the Debugger and try to post the entry again. The code encounters another error.
In the Debugger window, you can see that the error
occurred in codeunit 12, Gen. Jnl.-Post Line when the code
tried to read the last record,
FINDLAST in the G/L
To solve this, you must repeat the procedure described earlier and give codeunit 12, Gen. Jnl.-Post Line permission to read all the records in the G/L Entry table.
Log on to the database as TestUser, activate the Debugger, and try to post the entry again. This time the entry posts correctly.
Turn off the Debugger and try to post an entry for another department. You will receive a different error message informing you that you do not have write permission to the G/L Entry table. This means that your security filters work and you can only post entries for the ADM department.