Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Upload

Posted on by 3,027

Hi

  I have below code it is giving message records successfully loaded but it is not showing

Gen. Journal Line - OnAfterImportRecord()
"Journal Template Name" := 'GENERAL';
"Journal Batch Name" := 'TEST';

"Line No.":="Line No."+10000;
"Amount (LCY)":=Amount;

Ctr := Ctr + 1;

Thanks

*This post is locked for comments

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Upload

    Hi

      Why At the second record imported, Line No is always 0 . Secondly in earlier post u have written

    OnAfterImport AFTER the data is imported (but it’s not written to the db). When it is written to db. 

    Thirdly when the function is called if the function is called in AfterImport but record is still not written to db then how function gets the correct value of Line No.

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Upload

    Because this line of code you wrote:

    "Line No.":="Line No."+10000;

    is wrong.

    Here, at the first record Line No is 0 (data imported from external) and then you assign 0 + 10000 = 10000, the line is inserted.

    At the second record imported, Line No is always 0 (data imported from external), you assign 0 + 10000 = 10000, this Line No. now exists and you receive an error.

    A function is used to retrieve the last Line No. inserted in the table.

    P.S. I've suggested a function because it's more elegant and it's the best way to do for "code readability", but you can also write the code I've suggest you directly in OnAfterGetRecord without using a function.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Upload

    Hi

      Thanks . I want to know why we need to write function for incrementing Line No. Wht it does not work properly when we write it in OnAfter/OnBeforeImportRecord

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Upload

    OnBeforeImport is triggered BEFORE the data was imported, OnAfterImport AFTER the data is imported (but it’s not written to the db). Use OnAfterImport event to set your values.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Upload

    Hi Stefano

     What is the difference in writing function than in OnBeforeImportRecord/OnAferImportRecord .

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Upload

    The GetLineNo function must return an integer:

    Post.jpg

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Upload

    Hi

     I have written below code it gives error 'A variable was expected'.


    GenJnlLine.SETRANGE("Journal Template Name",'GENERAL');
    GenJnlLine.SETRANGE("Journal Batch Name",'GST-VINOD');
    if GenJnlLine.FINDLAST then
    exit(GenJnlLine."Line No." + 10000)
    else
    exit(10000);

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Upload

    In the OnAfterImport, use your code:

    Gen. Journal Line - OnAfterImportRecord()

    "Journal Template Name" := 'GENERAL';

    "Journal Batch Name" := 'TEST';

    "Line No.":=GetLineNo;

    "Amount (LCY)":=Amount;

    Ctr := Ctr + 1;

    After that, define the GetLineNo function in the dataport as previously described.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Upload

    Hi

     Kindly tell me if i have to write it in code alone. Then how it should be done

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Upload

    EXIT returns a value from a function (in my sample, it returns an integer that is the new line no for inserting the record).

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans