Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Last Record not getting totalled

Posted on by 3,027

Hi

  I have below data . With the below code Last Record Data not getting 

Date	Location	Amount 
04/01/2017	XYZ	6500
04/01/2017	XYZ	1
04/01/2017	XYZ	17500
06/01/2017	XYZ	16000
08/01/2017	XYZ	19306
09/01/2017	XYZ	88000


TEntry.RESET;
TEntry.SETCURRENTKEY("Location No.",Date);
TEntry.SETFILTER("Store No.","No.");
TEntry.SETRANGE(TEntry.Date,StDate,EndDate);

IF TEntry.FINDFIRST THEN BEGIN
  TempDate := TEntry.Date;
  Amount := 0;
  REPEAT
    IF TEntry.Date <> TempDate THEN BEGIN
      CDLine.INIT;
      CDLine.VALIDATE("Location No.","No.");
      CDLine.VALIDATE("Date",TempDate);
      CDLine.VALIDATE("Amount",Amount);
      CDLine.INSERT;
      TempDate := TEntry.Date;
      Amount := 0;
    END;
    Amount += TEntry."Amount";
  UNTIL TEntry.NEXT=0;
END;

*This post is locked for comments

  • Verified answer
    Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: Last Record not getting totalled

    Hi,

    In this you need to keep a track of entries that are already taken into the CDline table by putting a binary field say entry_created in SalesLineTable.

    Now, use the following code

    SalesLineTable.RESET;

    SalesLineTable.SETRANGE(entry_created,FALSE);

    If SalesLineTable.FINDFIRST THEN

    REPEAT

    CDline.RESET;

    CDline.SETRANGE(Date,SalesLineTable.PostingDate);

    CDline.SETRANGE(Location,SalesLineTable.Location);

    IF CDline.FINDFIRST THEN BEGIN

    CDline.Amount := CDline.Amount + SalesLineTable.Amount;

    CDline.MODIFY;

    SalesLineTable.entry_created := TRUE;

    SalesLineTable.MODIFY;

    END

    ELSE BEGIN

    CDline.INIT;

    CDline.Date := SalesLineTable.PostingDate;

    CDline.Amount := SalesLineTable.Amount;

    CDline.Location := SalesLineTable.Location;

    CDline.INSERT;

    SalesLineTable.entry_created := TRUE;

    SalesLineTable.MODIFY;

    END;

    UNTIL SalesLineTable.NEXT = 0;

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Last Record not getting totalled

    Hi

      I have below Data say in Sales Line table.

    Posting Date   Location          Amount

    04/01/2017 XYZ 6500

    04/01/2017 XYZ 1

    04/01/2017 XYZ 17500

    06/01/2017 XYZ 16000

    08/01/2017 XYZ 19306

    09/01/2017 XYZ 88000

    In Custom table i want that data should be inserted like this means grouping by Date & Location.

    04/01/2017 XYZ 24001

    06/01/2017 XYZ 16000

    08/01/2017 XYZ 19306

    09/01/2017 XYZ 88000

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: Last Record not getting totalled

    Hi jsshivalik,

    Could you be more specific more in terms of what you exactly want to do? If possible give some example.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Last Record not getting totalled

    As I have mentioned I am assuming those three as the Primary Key, if that is not your case then you just need to use the MODIFY statement.

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: Last Record not getting totalled

    RENAME function is used to modify the Value in the Primary Key Field.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Last Record not getting totalled

    Hi

     What does this line does

    CDLine.RENAME(TEntry.Date,TEntry."Location code",TEntry.Amount + CDLine.Amount);

    Thanks

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Last Record not getting totalled

    You might have to do something like this, in this I am assuming both tables has date, location code and Amount as the Primary Key.

    TEntry.RESET;

    TEntry.SETCURRENTKEY("Location code",Date);

    TEntry.SETRANGE(TEntry.Date,010117D,123117D);

    IF TEntry.FINDFIRST THEN BEGIN

     First := TRUE;

     REPEAT

       IF First OR (TEntry.Date <> OldDate) OR (TEntry."Location code" <> OldLocationCode) THEN BEGIN

         CDLine.INIT;

         CDLine.VALIDATE("Location code",TEntry."Location code");

         CDLine.VALIDATE(Date,TEntry.Date);

         CDLine.VALIDATE(Amount,TEntry.Amount);

         CDLine.INSERT;

       END ELSE BEGIN

         CDLine.RENAME(TEntry.Date,TEntry."Location code",TEntry.Amount + CDLine.Amount);

       END;

       First := FALSE;

       OldLocationCode := TEntry."Location code";

       OldDate := TEntry.Date;

     UNTIL TEntry.NEXT=0;

    END;

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Last Record not getting totalled

    what is the store no. ?  you are not storing Location code in the CDLine table

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: Last Record not getting totalled

    Yes. Wht is the issue in my code.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Last Record not getting totalled

    Are you trying to store the values in the CDline table group by location and Date.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans