Set filter without dataitem

gadzilla1gadzilla1 Member Posts: 316
Greetings,

I've checked out the COPYFILTER, SETFILTER posts and still haven't been able to figure out the following:

For Report 10056 I've added a textbox with SourceExpr FORMAT(SalesHeader.Status) in the Sales line, GroupHeader (1) area of the sections. That's displaying fine.

I'd like to filter on SalesHeader.Status to be able to see which orders are released or open.

Does anyone have any ideas?

Any help is appreciated. Thank you. gad1

Comments

  • krikikriki Member, Moderator Posts: 9,110
    Put the Status-field in property "ReqFilterFields" of the sales header.
    The user can then put a filter in it.

    If you want to do define it. Put in property DataItemTableView this:WHERE(Status=FILTER(Open|Released))

    Or in the "Sales Header" - OnPreDataItem()-trigger
    SETFILTER(Status,'%1|%2',Status::Open,Status::Released);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • gadzilla1gadzilla1 Member Posts: 316
    Thanks much for the reply. The suggestion was understood but unfortunately does not apply to my situation.

    The issue with this report is that "Sales Header" is not a dataitem...the only dataitems are Customer and Sales Lines.

    How do I allow a filter to a report without a Sales Header dataitem? SalesHeader only appears as a Global variable...?

    Thank you - gad1
  • kinekine Member Posts: 12,562
    You can check the header.status in OnAfterGetRecord after you get the Header for the line and Skip the lines which fulfill the condition...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    Exactly what I was thinking.

    Add to the request form and option filter "myfilterstatus" Open/Released.
    On the onAfterGetRecord.

    Salesheader.GET("Document Type","Document No.");

    now depending on what your request form filter was say OPEN in this case.
    the the say if myfilterstatus = open 
     then begin
      if salesheader.status = released
     then begin currReport.SKIP
    end
     else begin
      <report calculations>
    End;
    

    or maybe SHOWOUTPUT(false) not sure which is best.
    then add code for the opposite
    the the say if myfilterstatus = released
     then begin
      if salesheader.status = open
     then begin currReport.SKIP
    end
     else begin
      <report calculations>
    End;
    

    Quick & sloppy but you get the point

    Mabe one of the codemasters can clean it up :mrgreen:
  • SavatageSavatage Member Posts: 7,142
    or you can make a boolean on the request form.
    "MyFilterStatus"
    Check it for Open Orders Only of leave it unchecked for Releases Orders only.

    Create a Function called ReportCalculations & move all the report calc into the function. You will call the function when needs on the onaftergetrecord trigger with something like this.

    OnAfterGetRecord()
    SalesHeader.GET("Document Type","Document No.");
    
    IF MyFilterStatus
     THEN BEGIN
      IF SalesHeader.Status = 2
       THEN BEGIN CurrReport.SKIP;
      END
     ELSE BEGIN
    ReportCalculations;
     END;
    END
     ELSE BEGIN
      IF SalesHeader.Status = 1
       THEN BEGIN CurrReport.SKIP;
      END
     ELSE BEGIN
    ReportCalculations;
     END;
    END;
    

    http://savatage99.googlepages.com/10056 ... tus-NE.txt

    fob version available
  • gadzilla1gadzilla1 Member Posts: 316
    I started working on this prior to reading your posts...it works well. Rip it apart if you need to. :wink:

    I added a new dataitem referencing the Sales Header and named it DummySalesHeader. I set the required filter as Status.

    I created a text variable FilterString2.

    In the C/AL for OnPreReport() I added the following:

    FilterString2 := DummySalesHeader.GETFILTER(Status);

    In the C/AL for Sales Line - OnAfterGetRecord() I added:

    SalesHeader.GET("Document Type","Document No.");
    IF FilterString2 <> '' THEN BEGIN
    IF FilterString2 <> FORMAT(SalesHeader.Status) THEN CurrReport.SKIP;
    END;
  • SavatageSavatage Member Posts: 7,142
    The txt file I posted works - if you have a liscense that lets you import text files - else give me a open report # and i can save it in a # that works for youas a fob, so you can play around with it.

    Also if you don't want to move the reports original calculation formula into it's own function then just copy & paste the formula twice into the <reportcalculations> sections.

    If your way works too then great - there are usually more than 1 way to skin a cat. :shock:
  • gadzilla1gadzilla1 Member Posts: 316
    Thank you very much. I appreciate all of your help.
  • krikikriki Member, Moderator Posts: 9,110
    I'll give an example too:
    Create a boolean on the request form for Released orders and another for open orders. Like this you can select which you want to see and which not.
    Booleans:
    blnShowReleasedOrders
    blnShowOpenOrders

    OnAfterGetRecord()
    IF (recSalesHeader."Document Type" <> "Document Type") OR
        (recSalesHeader."No." <> "Document No.") THEN
      recSalesHeader.GET("Document Type","Document No.");
      // No need to do a GET if you already have the correct salesheader in memory
    
    CASE recSalesHeader.Status OF
      recSalesHeader.Status::Released: 
        IF NOT blnShowReleasedOrders THEN
          CurrReport.SKIP;
      recSalesHeader.Status::Open:
        IF NOT blnShowOpenOrders THEN
          CurrReport.SKIP;
    END;
    // PS : NEVER user something like "SalesHeader.Status = 0"
    // ALWAYS use "SalesHeader.Status = recSalesHeader.Status::Open"
    //   it is a lot easier to read the code
    
    // and if your code is quite long, best put it in a function.
    ReportCalculations();
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • gadzilla1gadzilla1 Member Posts: 316
    I did not see that there was another example posted...thank you all very much!

    gad1
Sign In or Register to comment.