Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Modifying records with tryFunctions

Posted on by 255

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

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Modifying records with tryFunctions

    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.

  • Jose Manuel Sola Profile Picture
    Jose Manuel Sola 90 on at
    RE: Modifying records with tryFunctions

    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" />

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Modifying records with tryFunctions

    Can you show me the error?

    Or check here:

    community.dynamics.com/.../using-try-functions-in-navision-2016

  • lynix_x Profile Picture
    lynix_x 255 on at
    RE: Modifying records with tryFunctions

    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;

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Modifying records with tryFunctions

    Yes it's possible...

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans