A typical error is thrown when the application is trying to issue some not allowed functions executed in their MODAL equivalent.
This error, then, is not a platform issue but a typical application one (sub-optimal code).
Typically, this is hard to catch at runtime since there might be nested code and, overall, conditional statement that may or may not lead to hit the modal functions.
How do you catch the fox, then? There might be 2 feasible way:
- Automated Tests.
The more tests you create – and execute them – the lower is the risk to smash your face in production at runtime.
That is the warm suggested solution.
- Use a dummy modal call in a try function before the real modal call.
Let me explain the trick. It might seem complex but actually it is not.
Create a codeunit whom is performing a call to itself under a try function.
codeunit 50112 "Write Transaction Checker"
{
trigger OnRun()
begin
end;
procedure Check() : Boolean;
begin
exit(not(CheckInternal));
end;
[TryFunction]
local procedure CheckInternal()
begin
if Codeunit.Run(50112) then;
end;
}
To simulate how the checker is working just create and execute a codeunit like the following
codeunit 50113 "Test Transaction Type"
{
trigger OnRun()
var
writeTransactionChecker : Codeunit "Write Transaction Checker";
item : Record Item;
isInWriteTransaction : Boolean;
begin
isInWriteTransaction := writeTransactionChecker.Check;
Message('Is in write transaction: %1',isInWriteTransaction);
item.LockTable();
item."No." := 'TESTITEM';
item.Insert();
isInWriteTransaction := writeTransactionChecker.Check;
Message('Is in write transaction: %1',isInWriteTransaction);
end;
}
The first message would not have a transaction started hence it will report a “No”.
At this stage, performing a modal action would be safe.
The second message is the result of a codeunit.run with a return value under a write transaction hence it will report a “Yes”.
You might want to use the Boolean value isInWriteTransaction to perform a different business process decision that do not involve a modal execution.

Report
All responses (