Call may write to the database inside a TryFunction

Properties
PC0041 Hidden Usage Code Fix Ignore Obsolete

Database changes made inside a [TryFunction] are not rolled back when an error is caught. PC0041 helps find calls whose effects are not known to be safe.

This diagnostic is disabled by default because it reports every custom procedure call and selected built-in methods without analyzing their implementations. Enable it when you want to review potential writes across your codebase; use PC0040 for direct record writes.

Example

[TryFunction]
local procedure TryPrepareCustomer(var Customer: Record Customer)
begin
    PrepareCustomer(Customer); // This procedure may write to the database [PC0041]
end;

If you know a call is safe and does not write to the database, suppress the diagnostic with a reason:

[TryFunction]
local procedure TryPrepareCustomer(var Customer: Record Customer)
begin
#pragma warning disable PC0041 // PrepareCustomer only validates values in memory.
    PrepareCustomer(Customer);
#pragma warning restore PC0041
end;

Enable the rule

Add PC0041 to your project’s .ruleset.json file. Info shows potential writes as informational messages:

{
    "name": "My Project Ruleset",
    "rules": [
        {
            "id": "PC0041",
            "action": "Info"
        }
    ]
}

When the diagnostic is reported

PC0041 is reported inside a TryFunction for every custom procedure call and for built-in Commit, Execute, Print, Run, RunModal, RunRequestPage, SaveAs, SaveAsExcel, SaveAsHtml, SaveAsPdf, SaveAsWord, SaveAsXml and Validate calls. It does not determine whether a custom procedure actually writes to the database.

See also