Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Opening not getting calculated properly

(0) ShareShare
ReportReport
Posted on by 3,077

Hi

 I have written the below code on G/L Entry pre data item but Opening is not calculated correct.

GLEntry0 is Record Type in C/Al Globals.
GLAccountNo is of Code DataType.

GLEntry0.RESET;
GLEntry0.SETFILTER("G/L Account No.",'%1',GLAccountNo);
GLEntry0.SETFILTER("Posting Date",'%1..%2',0D,StartDate-1);


IF GLEntry0.FINDFIRST THEN REPEAT
  Amt1 += GLEntry0.Amount;
UNTIL GLEntry0.NEXT=0;

When i write this line then it works fine.
GLEntry0.COPY("G/L Entry");
GLEntry0.SETFILTER("G/L Account No.",'%1',GLAccountNo);
GLEntry0.SETFILTER("Posting Date",'%1..%2',0D,StartDate-1);


Thanks

*This post is locked for comments

  • Verified answer
    Tina Menezes Profile Picture
    2,582 on at
    RE: Opening not getting calculated properly

    That's because COPY function creates a copy of your data item to GLEntry0 and then you are using setfilter, so it gets a reference to your records. But if you comment it, it does not get reference to your records in OnPreDataItem trigger. In OnAfterGetRecord trigger your report starts fetching one record after another and so I suggested you to put in OnAfterGetRecord trigger. Here your code should work without using COPY.

  • jsshivalik Profile Picture
    3,077 on at
    RE: Opening not getting calculated properly

    Hi

     I agree but when i write this line GLEntry0.COPY("G/L Entry");

    then it works. If i comment then it does not work.

    GLEntry0.COPY("G/L Entry");

    GLEntry0.SETFILTER("G/L Account No.",'%1',GLAccountNo);

    GLEntry0.SETFILTER("Posting Date",'%1..%2',0D,StartDate-1);

    Thanks

  • Suggested answer
    Amol Salvi Profile Picture
    18,694 on at
    RE: Opening not getting calculated properly

    Check Standard report 704 for how to get opening balance

    As well as write code on OnAfterGetrecord and check

  • Tina Menezes Profile Picture
    2,582 on at
    RE: Opening not getting calculated properly

    Hi

    You need to write this code in OnAfterGetRecord trigger of the report instead of OnPreDataItem trigger.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,850 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans