web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Issue with TryFunction in BC on-premise

(0) ShareShare
ReportReport
Posted on by 2,304 Moderator

Hi,

I'm facing an issue with TryFunction in BC on-premise. Unlike in BC online, it is not throwing an error during code execution.

Here's an example of my code:

procedure Test()
begin
    if (batchAllocation.FindSet()) then
        repeat begin
            if (DistributionProcess()) then begin
                ErrorInProcess := false;
            end
            else begin
                ErrorInProcess := true;
                RevertProcess();
            end;
        end;
        until batchAllocation.Next() = 0;
end;

[TryFunction]
procedure DistributionProcess()
begin
    // Perform various tasks
end;
The RunTime problem occurs when inserting records in the purchase header table

999.png

I would greatly appreciate any suggestions on how to resolve the issue in on-premise version.

Thank you in advance for your help

I have the same question (0)
  • Suggested answer
    Govinda Kumar Profile Picture
    2,304 Moderator on at
    RE: Issue with TryFunction in BC on-premise

    The problem has been resolved, and the issue mentioned above is explained in detail in this blog demiliani.com/.../

  • JJMc Profile Picture
    291 on at
    RE: Issue with TryFunction in BC on-premise

    Good morning.

    Try functions's behavior are diffrent in cloud and OnPrem, but you can change it:

    According to Microsoft:

    This behavior is different from the behavior in Microsoft Dynamics NAV 2016, which did not include this restriction by default. Therefore, you might encounter errors if you have application code that was written for Microsoft Dynamics NAV 2016 and you run the code in Microsoft Dynamics NAV 2017.

    In practice, this means that you should not include the following function calls inside a try function scope:

    Data Type

    Function

    Record and RecordRef

    - INSERT
    - MODIFY
    - MODIFYALL
    - RENAME
    - DELETE
    - DELETEALL
    - >ADDLINK
    - DELETELINK
    - DELETELINKS

    Database

    - COMMIT

    If you want to change this behavior, you can set the DisableWriteInsideTryFunctions setting in the CustomSettings.config file of the server instance to false. However, we recommend that you design your code to suit the default behavior instead.


    So you may find the CustomSettings.config file at: C:\Program Files\Microsoft Dynamics NAV\100\Service


    Once you find the file, open it (Make sure the service is stopped) and search for DisableWriteInsideTryFunctions in this file. Change it to false.



    Save and close the file and then start the service again. Now try the operation again and It must be fixed. Enjoy!!!

    Reference: docs.microsoft.com/.../handling-errors-by-using-try-functions

     Note

    This behavior is different from the behavior in Microsoft Dynamics NAV 2016, which did not include this restriction by default. Therefore, you might encounter errors if you have application code that was written for Microsoft Dynamics NAV 2016 and you run the code in Microsoft Dynamics NAV 2017.

    In practice, this means that you should not include the following function calls inside a try function scope:

    TABLE 1

    Data Type

    Function

    Record and RecordRef

    - INSERT
    - MODIFY
    - MODIFYALL
    - RENAME
    - DELETE
    - DELETEALL
    - >ADDLINK
    - DELETELINK
    - DELETELINKS

    Database

    - COMMIT

    If you want to change this behavior, you can set the DisableWriteInsideTryFunctions setting in the CustomSettings.config file of the server instance to false. However, we recommend that you design your code to suit the default behavior instead

    Discalimer: 

       

     

    I hope it is usefull.

  • Govinda Kumar Profile Picture
    2,304 Moderator on at
    RE: Issue with TryFunction in BC on-premise

    Thanks, JJMc2.. I'm glad to inform you that the issue is resolved, and I have found an alternative way to achieve my desired functionality that works both in the on-premise and on-cloud, thank you for your response.

  • JJMc Profile Picture
    291 on at
    RE: Issue with TryFunction in BC on-premise

    Just out of curiosity. Could you please share how you solve it? Using a codeunit for this purpose?

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans