Running a report from a function

kwbburmeisterkwbburmeister Member Posts: 15
Hello everyone,

I need some help running a report the way I want it to. I created a form, from which I want to run a report. In this form, I'm setting filters based on an option-field. Now I want to run a report with the option selected in the form.

The form filters the Sales Invoice Header. E.g. the user selects Netherlands from my option field, a function is setting filters on the country, the VAT Code and some other fields. My report creates a virtual invoice, in which I want to control the invoice receiver based on the option selected in the form. What I did: In my report I created a function with a rec-var and an option-var, which writes the local var from the function into a global variable for my report, in my form I'm calling the function with the filtered rec and the option selected. Now my problem is, that I don't know how to run the report after calling the function. I think I have to run in directly from my function, but how can I do this?

This is how my function within the report looks like now:
InvRec := InvAdress;
//InvRec is the global option-var, InvAdress is the local option-var
REPORT.RUNMODAL(77239,TRUE,TRUE,InvoiceHeaders);
//InvoiceHeaders is the local Rec-var

Thank you very much for your help!

Comments

  • vijay_gvijay_g Member Posts: 884
    see if you want to assign filter to DataItem(in your report) from the form then check "Voucher Printing Report" how Document no. passing and if you want to set any other filter(Parameter) based on calling form then create a function in report and setparameter to this function from form and use these parameter value to your filter.

    for more detail you can search for this topic in forum....
  • sresre Member Posts: 62
    What I did: In my report I created a function with a rec-var and an option-var, which writes the local var from the function into a global variable for my report, in my form I'm calling the function with the filtered rec and the option selected. Now my problem is, that I don't know how to run the report after calling the function.
    I think you'll have to define the report as an object in your form and use it like that:
    repTest.Def(Param1, Param2);  // Function Def to pass the 2 parameters over to the report
    repTest.RUNMODAL;
    
    Is that what you're looking for?

    Sascha
  • kwbburmeisterkwbburmeister Member Posts: 15
    I got closer to solving my problem. But I forgot to mention one thing:

    In my form I created a button, which - pushed - sets the selected Lines on marked (SETSELECTIONFILTER). With the last answer on my post I get the correct option in my report. When I call my function with the rec-variable, the report still shows data for all lines (my report is based on the "Sales Invoice Header" table).
    I'm not getting the clue how to filter the DataItem in my report to only the marked lines from my function!

    Thanks in advance!
  • pduckpduck Member Posts: 147
    For this effect you need a function in your report which accepts a record variable by reference. Call this function with your "selected" record variable before you run the report. Inside the function you assign the variable with COPY to a global variable in your report which will be used as filter for your corepsonding DataItem. Instead of a normal reference between records the function COPY also assigns marks. Check the help also.
  • mrsamrsa Member Posts: 35
    I use this kind of code
    (rep is report,
    NewRec is record same as Form data source):



    CLEAR(rep);
    CurrForm.SETSELECTIONFILTER(NewREC);
    NewREC.MARKEDONLY(TRUE);
    rep.SETTABLEVIEW(NewREC);
    rep.RUNMODAL;
    Wo.MARKEDONLY(TRUE);
    Rep.SETTABLEVIEW(Wo);
    Rep.RUNMODAL;
  • mrsamrsa Member Posts: 35
    Mistiped (double paste), correct is:
    use this kind of code
    (rep is report,
    NewRec is record same as Form data source):



    CLEAR(rep);
    CurrForm.SETSELECTIONFILTER(NewREC);
    NewREC.MARKEDONLY(TRUE);
    rep.SETTABLEVIEW(NewREC);
    rep.RUNMODAL;
  • vijay_gvijay_g Member Posts: 884
    Send the Rec Var as a parameter in function that you are using with SETSELECTIONFILTER and use this rec var in report.
    another way you can.....
    ReportVar.SETTABLEVIEW(RecVar of SETSELECTIONFILTER);
    
    according to your requirment i recommended you to use second way.
  • kwbburmeisterkwbburmeister Member Posts: 15
    Thank you all very much! The SETTABLEVIEW-Function did it for me. I changed my function to only take the option.

    Now my code in the form looks like (the lines are already marked at this point):

    CLEAR(Rep);
    Rep.GetInvAdress(InvoiceFilter);
    Rep.SETTABLEVIEW(Rec);
    Rep.RUNMODAL;

    The function in the report:

    GlobOptionVar := LocOptionVar;

    And it works perfectly!!

    Thanks again!
  • vaprogvaprog Member Posts: 1,139
    Just a somewhat off topic remark:

    Do not use MARKEDONLY(TRUE) in connection with SETSELECTIONFILTER. SetSelectionFilter sets MarkedOnly(True) *IF* it is using marks. It is not using marks if either all or no records are selected. If all records are selected, SetSelectionFilter is a NOP, if none is selected, SetSelectionFilter is equivalent to SetRecordFilter.
  • nvermanverma Member Posts: 396
    I kinda have to do the same thing. But i dont understand what most of you guyz are talking about?

    Is there any tutorial that shows how to do it or is there a step by step guide as to how I can do this. I am sorta a newbie at NAV thats why I am sorta lost...
  • SavatageSavatage Member Posts: 7,142
    Do you have a developers license?
  • DenSterDenSter Member Posts: 8,305
    nverma wrote:
    I am sorta a newbie at NAV thats why I am sorta lost...
    You keep pushing for people to give you the exact code, or to explain full concepts to you. If you work for a NAV partner then you should have a senior who explains these things to you. If you work at a customer you should get your partner involved to receive some training. At some point, you also have to start learning how to figure these things out yourself.

    There's this thing called the "C/SIDE Reference Guide", it's in the Classic client under the help menu. Open it, go to the search page and type in keywords that you want to know more about. There are tons of examples and sample code in there. Go to the online help system, there are tons of walkthroughs and tutorials in there.
  • nvermanverma Member Posts: 396
    Being honest, I have read the guide like so many times. For SETSELECTIONFILTER, all it says is: "Notes the records that the user has selected on the form, marks those records in the table specified, and sets the filter to "marked only"."

    What I want to know is where does it save this information?? How can I retrieve this info?

    Its not very detailed, I feel. Maybe thats just the newbie aspect of me talkign who doesnt know that much.
  • DenSterDenSter Member Posts: 8,305
    I did a quick search on SETSELECTIONFILTER here on Mibuso and got back 79 results. A quick scan of some of those gave me plenty of topics where there are code examples.

    I also did a quick google search and got back almost 3000 results on "SETSELECTIONFILTER Navision".

    Surely there is something you can use in there.

    These forums are not intended to provide a full explanation of an entire concept. You need to do some of the legwork yourself, and come with specific questions.
Sign In or Register to comment.