Skipping records when dispalying a form

poppinspoppins Member Posts: 647
Hi everyone,
I have a form for which I want to skip certain records.
In the OnAfterGetRecord trigger, there is a code that calculates a decimal varaiable X.
I want to be able to display only the records for which X > 0.
How can I achieve that?
Thanks in advance :)

Comments

  • geordiegeordie Member Posts: 655
    As far as I know there's no way to skip record in a form (like how you could do in a report): a solution can be in OnOpenPage to mark the records adding code like this:
    IF FINDSET THEN
      REPEAT
        // Calculate decimal
        MARK(X > 0);
      UNTIL NEXT = 0;
    
    MARKEDONLY(TRUE);
    IF FINDFIRST THEN;  //For auto-placement on first record
    
  • jglathejglathe Member Posts: 639
    Hi,

    it is possible, but not really easy. I have such code in my chart of accounts to select the accounts which are to be displayed (those marked and those that have entries in selected accounting periods). Basically you need to implement your own OnFindrecord/OnNextRecord functions. There are some catches in the logic to do so:

    1. Clipping: When you reach the first or the last record of your (filtered) table, these might not be valid entries (X<=0). You have to go backwards until you find a valid record.

    2. Steps: OnNextRecord can jump in steps <> 1 or -1. To fulfill the request you have to examine every record in the desired direction and only count the valid ones as a step.

    With this it should work.

    As an example, the copy/paste source from my chart of accounts form:
    Form - OnOpenForm()
    //03s gl
    SETRANGE("Date Filter",0D,WORKDATE);
    //03e gl
    //04s gl
    L_AccPeriod1.SETCURRENTKEY("Show in Account List");
    L_AccPeriod1.SETRANGE("Show in Account List",TRUE);
    IF L_AccPeriod1.FIND('-') THEN BEGIN
      ShowStartDate:=L_AccPeriod1."Starting Date";
      L_AccPeriod1.FIND('+');
      L_AccPeriod2.GET(L_AccPeriod1."Starting Date");
      IF L_AccPeriod2.NEXT=0 THEN BEGIN
        SETRANGE("Has Entries Date Filter",ShowStartDate,31129999D);
      END ELSE BEGIN
        SETRANGE("Has Entries Date Filter",ShowStartDate,L_AccPeriod2."Starting Date"-1);
      END;
    END;
    ShowWithEntries:=TRUE;
    //04e gl
    
    Form - OnCloseForm()
    
    Form - OnQueryCloseForm() : Boolean
    
    Form - OnActivateForm()
    
    Form - OnDeactivateForm()
    
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    //04s gl
    IF ShowWithEntries THEN BEGIN
      L_found:=FIND(Which);
      IF L_found THEN BEGIN
        CALCFIELDS("Has Entries");
        "Has Entries":=("Has Entries" OR "Show Always") AND (NOT Blocked);
        L_found:="Has Entries";
      END;
      IF NOT L_found THEN BEGIN
        CASE Which OF
          '-': BEGIN
            //06s gl
            L_found:=NextRec(Rec,1)=1;
            //06e gl
          END;
          '+': BEGIN
            //06s gl
            L_found:=NextRec(Rec,-1)=-1;
            //06e gl
          END;
          '=><': BEGIN
            L_found:=NextRec(Rec,1)<>0;
            IF NOT L_found THEN BEGIN
              L_found:=NextRec(Rec,-1)<>0;
            END;
          END;
        END;
      END;
      EXIT(L_found);
    END ELSE
      EXIT(FIND(Which));
    //04e gl
    
    Form - OnNextRecord(Steps : Integer) : Integer
    //04s jgl
    IF ShowWithEntries THEN BEGIN
      EXIT(NextRec(Rec,Steps));
    END ELSE
      EXIT(NEXT(Steps));
    //04e jgl
    
    Form - OnAfterGetRecord()
    
    Form - OnAfterGetCurrRecord()
    
    Form - OnBeforePutRecord()
    
    Form - OnNewRecord(BelowxRec : Boolean)
    SetupNewGLAcc(xRec,BelowxRec);
    
    Form - OnInsertRecord(BelowxRec : Boolean) : Boolean
    
    Form - OnModifyRecord() : Boolean
    
    Form - OnDeleteRecord() : Boolean
    
    Form - OnTimer()
    
    Form - OnCreateHyperlink(VAR URL : Text[1024])
    
    Form - OnHyperlink(URL : Text[1024])
    
    __04 gl 04.01.2006()
    
    NextRec(VAR L_Rec : Record "G/L Account";L_Steps : Integer) : Integer
    //06s gl
    L_Rec2.COPY(L_Rec);
    REPEAT
      L_DeltaSteps:=NextRecSingleStep(L_Rec2,sgn(L_Steps));
      L_TempSteps+=L_DeltaSteps;
    UNTIL (L_DeltaSteps=0) OR (L_TempSteps=L_Steps);
    IF L_TempSteps<>0 THEN BEGIN
      //07s gl
      //Clipping: Oberer oder unterer Rand wurden erreicht, bevor die Anzahl Schritte ausgeführt wurde. L_Rec2
      //steht auf dem ersten/letzten Datensatz, der nicht notwendiger Weise gültig sein muss. L_Rec2 wird geprüft,
      //und falls ungültig wird ein Schritt zurückgefahren.
      IF L_TempSteps<>L_Steps THEN BEGIN
        L_Rec2.CALCFIELDS("Has Entries");
        L_Rec2."Has Entries":=(L_Rec2."Has Entries" OR L_Rec2."Show Always") AND (NOT L_Rec2.Blocked);
        IF NOT L_Rec2."Has Entries" THEN BEGIN
          IF NextRecSingleStep(L_Rec2,-sgn(L_Steps))<>-sgn(L_Steps) THEN
            EXIT(0);
        END;
      END;
      //07e gl
      L_Rec.COPY(L_Rec2);
      EXIT(L_TempSteps);
    END ELSE
      EXIT(0);
    //06e gl
    
    sgn(Wert : Integer) : Integer
    IF Wert<>0 THEN
      EXIT(ROUND(Wert/ABS(Wert),1))
    ELSE EXIT(0);
    
    __06 gl 14.01.2006()
    
    NextRecSingleStep(VAR L_Rec : Record "G/L Account";L_Steps : Integer) : Integer
    WITH L_Rec DO BEGIN
      L_TempSteps:=NEXT(L_Steps);
      IF L_TempSteps<>L_Steps THEN BEGIN
        EXIT(0);
      END ELSE BEGIN
        CALCFIELDS("Has Entries");
        "Has Entries":=("Has Entries" OR "Show Always") AND (NOT Blocked);
        IF NOT "Has Entries" THEN BEGIN
          REPEAT
            L_TempSteps:=NEXT(L_Steps);
            IF L_TempSteps<>0 THEN BEGIN
              CALCFIELDS("Has Entries");
              "Has Entries":=("Has Entries" OR "Show Always") AND (NOT Blocked);
            END ELSE
              EXIT(0);
          UNTIL "Has Entries";
          EXIT(L_Steps);
        END ELSE
          EXIT(L_Steps);
      END;
    END;
    

    with best regards

    Jens
Sign In or Register to comment.