Hey,
is it possible to modify a record within a tryFunction?. I saw some tutotrials for insert command, but not for modify.
*This post is locked for comments
Hey,
is it possible to modify a record within a tryFunction?. I saw some tutotrials for insert command, but not for modify.
*This post is locked for comments
Manuel is right, sorry but I forgot the NAV version (I was thinking you was working with NAV 2016).
From NAV 2017, because changes made to the database by a try function are not rolled back, you should not include database write transactions within a try function. By default, the Microsoft Dynamics NAV Server configuration prevents you from doing this. If a try function contains a database write transaction, a runtime error occurs.
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:
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.
Hi !
Maybe you must modify the customsetting.config ...with this value to false...
<!--
Specifies whether to raise an error when C/AL code that is executed in the scope of a TryFunction writes to the database.
It is recommended to update the C/AL code to avoid writing to the database from a TryFunction. However, in cases where this is not possible, setting this value to false allows TryFunctions to write to the database, and behave as they did in Dynamics NAV 2016.
-->
<add key="DisableWriteInsideTryFunctions" value="false" />
Can you show me the error?
Or check here:
community.dynamics.com/.../using-try-functions-in-navision-2016
Hey stefano,
thanks for quick reply.
i have following code, but it gives me error that i cannot use modify within tryfunction
this is my code:
[TryFunction]Check(No : Code[20];PaymenCode : Text[50];PaymentID : Text[50])
PoHeader.SETRANGE(PoHeader."No.", AppendixNo);
IF PoHeader.FIND('-') THEN BEGIN
PoHeader.VALIDATE("Payment Method Code", PaymenCode );
PoHeader.VALIDATE("Payment Reference", PaymentID );
PoHeader.VALIDATE("Payment Identification",PaymentID);
PoHeader.MODIFY(TRUE);
END;
Yes it's possible...
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156