Problem with Repeat ..Until in Report 120

sunnyksunnyk Member Posts: 280
Hi Experts,

I m trying to have latest Customer Comments on Report 120. I wrote the following Code on OnAfterGet Record of Customer Dataitem. For few customer range this is working fine but when i run the report for every customer it is taking ages to generate the 1st page itself. Just pls have a look on the code and suggest me where i m wrong.
gtComments.RESET;
gtComments.SETRANGE(gtComments."Table Name",gtComments."Table Name"::Customer);
gtComments.SETRANGE(gtComments."No.","No.");
IF gtComments.FINDLAST THEN
  IF gtComments.Date = 0D THEN BEGIN
    REPEAT
      gtComments.NEXT(-1);
    UNTIL gtComments.Date <> 0D;

    REPEAT
      Comments := Comments + ''+gtComments.Comment;
    UNTIL  gtComments.NEXT = 0;
  END ELSE
  Comments := gtComments.Comment;

Answers

  • kinekine Member Posts: 12,562
    What about sorting the comments in descending order and use something like that:
    gtComments.RESET;
    gtComments.SETRANGE(gtComments."Table Name",gtComments."Table Name"::Customer);
    gtComments.SETRANGE(gtComments."No.","No.");
    gtComments.ASCENDING(false);
    
    if gtComments.FIND('-') then  //FINDSET cannot be used when ASCENDING(false)
    repeat
      Comments := gtComments.Comment + ' ' + Comments;
    until (gtComments.Date <> 0D) or (gtComments.NEXT=0);
    

    In your code, you are misusing the FINDLAST - it is used to getting the last record when you are not planning to go through the rest. Better will be to use FIND('+') in this case...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • sunnyksunnyk Member Posts: 280
    Thanks Kine for your reply. Ok If i use Find('+') in place of findlast, then is my code ok?
  • sunnyksunnyk Member Posts: 280
    I think you didnt get what i m trying to acheive.
    Suppose for a particular customer we have several comments, but because Comment Coloumn has Text limit so what the user do it comes to the next line and insert there without putting the Date.

    So suppose for a customer i have 100 lines of comments and 97th line only has the date and comments. the 98th , 99th and 100th lines have only comments but no date because it is in continuation with 97th.

    So my objective is to get the last line with date as the first line of the comment to print + all the following lines without Dates.

    Ex. Comment Line Table

    Date .................................. Line No................................... Comments
    22/12/03 ........................... 100000 ................................... Testing Comments
    ...................................... 200000 ................................... Another Testing Comments...


    25/12/04........................... 100000 ................................... New Comments, too short to place full
    ...................................... 200000 ................................... Comments here, thats why i have 3
    ...................................... 300000 ................................... Lines. thank you.

    Now what i want on Report is New Comments, too short to place full Comments here, thats why i have 3 Lines. thank you.
  • sunnyksunnyk Member Posts: 280
    Sorry kine, without checking your code i just put my comments. Thanks again today i learnt a new thing.
    Thanks a lot Kine.
  • kinekine Member Posts: 12,562
    You are welcome... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.