COMMIT or SELECTLATESTVERSION ?

EugeneEugene Member Posts: 309
i've been finding various places in Navision cusomization code where COMMIT is used to see in one record variable Rec1 changes previously made in another record of the same table Rec2:
Rec2.MODIFY
COMMIT
Rec1.GET

I wonder should not SELECTLATESTVERSION be used instead of COMMIT in such cases? Will it work correctly both in Native and MS SQL databases ?

Comments

  • ara3nara3n Member Posts: 9,256
    you don't need to use either.
    Rec2.MODIFY
    Rec1.GET
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,305
    COMMIT should be avoided in the middle of transactions. If Rec1.GET doesn't work, and you need Rec2's values in Rec1, then why not do Rec1 := Rec2?

    Besides, right after you do Rec2.MODIFY, it should be available in Rec1, so that code should work without the COMMIT.
  • robastarobasta Member Posts: 11
    Hello all,


    I have a codeunit that populates the sales header and lines, after inserting (two headers) it then posts (using sales-post cu81) them one after the other.

    If the first one posts successfully and then the second one does not post, the first one should be rolled back. how do i achieve this? i am thinking of using commit like so:
    beginwritetransaction;
     salepost.run(SalesHeader1);
     salepost.run(SalesHeader2);
    commit;
    
  • ajhvdbajhvdb Member Posts: 672
    The first one will be commited in NAV. Sorry..
  • kinekine Member Posts: 12,562
    robasta wrote:
    Hello all,


    I have a codeunit that populates the sales header and lines, after inserting (two headers) it then posts (using sales-post cu81) them one after the other.

    If the first one posts successfully and then the second one does not post, the first one should be rolled back. how do i achieve this? i am thinking of using commit like so:
    beginwritetransaction;
     salepost.run(SalesHeader1);
     salepost.run(SalesHeader2);
    commit;
    

    You need to add some "flag" which is used in CU80 to skip the COMMIT at the end of the processing. And there is another commit during "releasing" the order - you need to assing posting nos. manually and "release" the order if you need to skip this commit... - but you need to "skip" the commit only in your specific case, not in common posting etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.