Processing data in GroupFooter or GroupHeader

vandangvandang Member Posts: 101
I would like to group item by Inventory posting group in Value Entry, so I decided put all text box to Group Footer (or Group Header still ok). The simple process, ex. counting line for each item worked well, report can loop through each item and show all item by group. But I want to put some code to filter data, report cannot loop, it just run at the first item and stop ](*,) . Please help!

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    vandang wrote:
    But I want to put some code to filter data, report cannot loop, it just run at the first item and stop ](*,) . Please help!
    Can you share the code and where did you write it?
  • vandangvandang Member Posts: 101

    Can you share the code and where did you write it?

    Thanks for replying, I put it on Value Entry, GroupFooter - OnPreSection here is my code :
    STT := FALSE;
    
    IF (STT = FALSE) THEN BEGIN
    IF ("Invoiced Quantity" <> 0) THEN BEGIN
        No += 1;
        STT := TRUE;
      END;
    END;
    
    ItemNo := "Value Entry"."Item No.";
    
    Item.SETRANGE(Item."No.","Value Entry"."Item No.");
    IF Item.FINDFIRST THEN
    REPEAT
      ItemName := Item."Description 2";
    UNTIL Item.NEXT = 0;
    
    //Getting GLAccount for Inventory
    InvPostSetup.SETRANGE("Invt. Posting Group Code", "Value Entry"."Inventory Posting Group");
    IF InvPostSetup.FINDFIRST THEN
      InvAcc := InvPostSetup."Inventory Account";
      
       IF (BegDat = 0D) THEN BEGIN
       GLEntry.SETRANGE("Posting Date",040111D,043011D);
       GLEntry.SETRANGE("G/L Account No.",InvAcc);
       IF GLEntry.FINDSET THEN
       REPEAT
         "Value Entry".SETRANGE("Entry No.",GLEntry."Value Entry No.");
         "Value Entry".SETRANGE("Value Entry"."Item No.",ItemNo);
         IF "Value Entry".FINDFIRST THEN BEGIN
    
         Adjtemp := "Adjusted Cost";
           IF (GLEntry.Amount <> "Adjusted Cost") THEN BEGIN
             ExpectedCost := ABS("Adjusted Cost");
             Adjtemp := 0;
           END;
    
          AdjCost := Adjtemp + ExpectedCost + AdjCost;
          ValQty := ValQty + "Valued Quantity";
          
          IF ("Item Ledger Entry Type" IN
            ["Item Ledger Entry Type"::Purchase,"Item Ledger Entry Type"::"Positive Adjmt."])
          THEN BEGIN
            ValueOfInvIncreases := ValueOfInvIncreases + Adjtemp + ExpectedCost;
            InvPosAdjustments := InvPosAdjustments + "Valued Quantity";
          END ELSE BEGIN
            CostOfInvDecreases := CostOfInvDecreases + Adjtemp + ExpectedCost;
            InventoryNegAdjustments := InventoryNegAdjustments + "Valued Quantity";
         END;
         ExpectedCost := 0;
        END;
       UNTIL GLEntry.NEXT = 0;
       END;
    

    I also put the same code in Value Entry - OnAfterGetRecord, but still get the same result
  • MBergerMBerger Member Posts: 413
    vandang wrote:

    Can you share the code and where did you write it?

    Thanks for replying, I put it on Value Entry, GroupFooter - OnPreSection here is my code :
    STT := FALSE;
    
    IF (STT = FALSE) THEN BEGIN
    IF ("Invoiced Quantity" <> 0) THEN BEGIN
        No += 1;
        STT := TRUE;
      END;
    END;
    
    ItemNo := "Value Entry"."Item No.";
    
    Item.SETRANGE(Item."No.","Value Entry"."Item No.");
    IF Item.FINDFIRST THEN
    REPEAT
      ItemName := Item."Description 2";
    UNTIL Item.NEXT = 0;
    
    //Getting GLAccount for Inventory
    InvPostSetup.SETRANGE("Invt. Posting Group Code", "Value Entry"."Inventory Posting Group");
    IF InvPostSetup.FINDFIRST THEN
      InvAcc := InvPostSetup."Inventory Account";
      
       IF (BegDat = 0D) THEN BEGIN
       GLEntry.SETRANGE("Posting Date",040111D,043011D);
       GLEntry.SETRANGE("G/L Account No.",InvAcc);
       IF GLEntry.FINDSET THEN
       REPEAT
         "Value Entry".SETRANGE("Entry No.",GLEntry."Value Entry No.");
         "Value Entry".SETRANGE("Value Entry"."Item No.",ItemNo);
         IF "Value Entry".FINDFIRST THEN BEGIN
    
         Adjtemp := "Adjusted Cost";
           IF (GLEntry.Amount <> "Adjusted Cost") THEN BEGIN
             ExpectedCost := ABS("Adjusted Cost");
             Adjtemp := 0;
           END;
    
          AdjCost := Adjtemp + ExpectedCost + AdjCost;
          ValQty := ValQty + "Valued Quantity";
          
          IF ("Item Ledger Entry Type" IN
            ["Item Ledger Entry Type"::Purchase,"Item Ledger Entry Type"::"Positive Adjmt."])
          THEN BEGIN
            ValueOfInvIncreases := ValueOfInvIncreases + Adjtemp + ExpectedCost;
            InvPosAdjustments := InvPosAdjustments + "Valued Quantity";
          END ELSE BEGIN
            CostOfInvDecreases := CostOfInvDecreases + Adjtemp + ExpectedCost;
            InventoryNegAdjustments := InventoryNegAdjustments + "Valued Quantity";
         END;
         ExpectedCost := 0;
        END;
       UNTIL GLEntry.NEXT = 0;
       END;
    

    I also put the same code in Value Entry - OnAfterGetRecord, but still get the same result
    you are doing a FindFirst on your value entry Dataitem, Define a new record for that to use in your code. Another problem is that i think you have forgotten a BEGIN and END after you get your Inventory Posting Group.

    Furthermore, why are you using SETRANGE and FINDFIRST on primary keys ? I'd replace
    Item.SETRANGE(Item."No.","Value Entry"."Item No.");
    IF Item.FINDFIRST THEN
    REPEAT
      ItemName := Item."Description 2";
    UNTIL Item.NEXT = 0;
    
    with
    IF not Item.Get("Value Entry"."Item No.") THEN
      Item.Init ;
    ItemName := Item."Description 2" ;
    
    And that also goes for when you are getting your Inventory Posting Group.
  • vandangvandang Member Posts: 101
    Thanks MBerger,

    This code is already run ok, difference is the structure of the old one is: DataItem Level
    Item
    Value Entry

    Because user change Inventory posting group when posting, so this structure cannot get the value in Value entry table, so I just use only one Data Item is Value Entry. Here I should transfer code to this new report and don't understand why it don't loop and show all item with my code.
  • vandangvandang Member Posts: 101
    Thanks MBerger again,
    vandang wrote:
    Define a new record for that to use in your code
    Just as you said. I define the new one and it ok, thanks you so much!
Sign In or Register to comment.