Options

Calling procedures in a middle of transaction

babak2000irbabak2000ir Member Posts: 5
I'm stocked somewhere fellas,

Imagine a header-Lines structure, by validating some fields on the lines, I'll call a procedure to update header (procedure will look at the lines to update header based on the line values), when I call the procedure, procedure query the line table, but as I called the procedure during the line transaction, new changes are not stored yet.

I used Commit, but apparantly commit is not working inside the Modify Trigger.

I also taught about checking a flag while changing the line, and call the procedure later, as procedure changes something inside the header, I cannot call it on Page or List (onAfterGetRecord), I'll get a error.

Would you please give me some Ideas?

Comments

  • Options
    pdjpdj Member Posts: 643
    COMMIT works fine inside an OnModify trigger. But the record isn't modified in the table before the OnModify trigger is finished. You often make additional changes to the Rec inside an OnModify trigger, then it wouldn't make sense if it is modified in the table before the OnModify trigger. If you need to call a function that requires the record to be modified, you will simply need to call MODIFY without TRUE ;-) inside your OnModify trigger. Just make sure the rest of your code supports it. It might cause problems for the Change Log, if that is enabled for the table...

    Edit: An even better solution might be to pass the record as a parameter to the function, but it depends on the needs.
    Regards
    Peter
  • Options
    ara3nara3n Member Posts: 9,256
    Never use COMMIT in your code.

    The only place it makes sense it if you are writing your own posting routine. Or you are batch processing.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    babak2000irbabak2000ir Member Posts: 5
    edited 2011-03-24
    pdj wrote:
    COMMIT works fine inside an OnModify trigger. But the record isn't modified in the table before the OnModify trigger is finished. You often make additional changes to the Rec inside an OnModify trigger, then it wouldn't make sense if it is modified in the table before the OnModify trigger. If you need to call a function that requires the record to be modified, you will simply need to call MODIFY without TRUE ;-) inside your OnModify trigger. Just make sure the rest of your code supports it. It might cause problems for the Change Log, if that is enabled for the table...

    Edit: An even better solution might be to pass the record as a parameter to the function, but it depends on the needs.

    Even without testing I'm sure this works, Thank you, I will confirm if it worked for me

    The process is really independent so sending rec as a refrence was not possible, but problem completely solved, abd thank you for the heads up about: Just make sure the rest of your code supports it. this is so important, Really thanks, you helped me a lot :)
  • Options
    babak2000irbabak2000ir Member Posts: 5
    ara3n wrote:
    Never use COMMIT in your code.

    The only place it makes sense it if you are writing your own posting routine. Or you are batch processing.

    Thanks, I'll have it in my mind. I believe this is true, sometimes it really tickles me to use Commit, but I usually try to avoid, this Commit thing is kind of like "GOTO"!
  • Options
    krikikriki Member, Moderator Posts: 9,098
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    RoelofRoelof Member Posts: 377
    So, if a COMMIT has been used in CU-2 called from CU-1 and in CU-2 there is an error, is the data written in CU-2, stored to the database or is there a rollback after the error and nothing is written to the db, so like:

    CU-1:
    .
    .

    IF not CU-2 then //CU-2 contains a COMMIT
    UpdateError;
    .
    Roelof de Jonghttp://www.wye.com
  • Options
    ara3nara3n Member Posts: 9,256
    If CODEUNIT.RUN Then automatically issues a commit.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    DenSterDenSter Member Posts: 8,304
    Any time that a COMMIT is called it writes everything to the database. If you run into an error later, it will roll back to the last COMMIT. You could write code that 'fixes' any data that you're left with after half of a transaction, but technically that is NOT a rollback.
Sign In or Register to comment.