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.