Hi Folks,
I am back with another solution for an error, I came across this error several times even before but this time I am posting here for your help :) . The error description is as follow:

 

Microsoft Dynamics NAV
---------------------------

Call to the function 'INSERT' is not allowed inside the call to 'FunctionName' when it is used as a TryFunction.
---------------------------
OK
---------------------------



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 TypeFunction
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: https://docs.microsoft.com/en-us/dynamics-nav/handling-errors-by-using-try-functions