Report Sales Header & Sales Header Archive

Lump86Lump86 Member Posts: 4
Hello,

i need to do a report showing all sales orders from table 36 "Sales Header" and table 5107 "Sales Header Archive".
I have these tables as seperate two dataitems in the report.
An order which is created and saved in table 36 and archived in table 5107 at the same time should not be printed twice in the report, so only one time, saying from table 36. How can I realize that in C/AL Code?

I thought of SETRANGE function, but I am not sure. I appreciate any help! Thank you very much.
Regards
Lump86

Comments

  • vaprogvaprog Member Posts: 1,141
    Hi Lump86,

    how are your sorting needs? Do you have to alternate records from one and the other table, or can you just print records from one, then records from the other?
    With alternating record source you need a buffer table. You probably be able to single out unwanted records on insert to the buffer table.

    If one after the other (both dataitems have the same DataItemIndent), set filters on Sales Header from "Sales Header Archive" and use ISEMPTY like this:
    [Sales Header Archive - OnPreDataItem()]
    COPYFILTERS("Sales Header"); // use the same filters
    FILTERGROUP(10); // avoid conflicts with filters set by the user
    "Sales Header".FILTERGROUP(10);
    
    [Sales Header Archive - OnAfterGetRecord()]
    "Sales Header".SETRANGE("Document Type","Document Type");
    "Sales Header".SETRANGE("Document No.","Document No.");
    IF NOT "Sales Header".ISEMPTY THEN
      CurrReport.SKIP;
    
    // skip all versions but the newest
    SETRANGE("Document Type","Document Type");
    SETRANGE("Document No.","Document No.");
    FINDLAST;
    SETRANGE("Document Type");
    SETRANGE("Document No.");
    
    [Sales Header Archive - OnPostDataItem()]
    // clean-up
    "Sales Header".SETRANGE("Document Type");
    "Sales Header".SETRANGE("Document No.");
    "Sales Header".FILTERGROUP(0);
    FILTERGROUP(0);
    
  • Lump86Lump86 Member Posts: 4
    Hi vaprog,

    thanks for your help :thumbsup:
    Regarding sorting needs: Both of my dataitems share the same intent.
    So if a sales order is created and archived at the same time (same record in both tables, i.e. Tables 36 and 5107) only the record from Table 36 should be printed in the report.
Sign In or Register to comment.