Options

How can I run a Report object from a codeunit while request page set to false by parameter?

atpiyushatpiyush Member Posts: 12
Though, I can run report by making a new function in report itself to initialize report and then run it. I call that function from codeunit as per requirement. Even, report run fine but the only issue is that if I do not want to show request page; then report does not run. It shows on RTC that it is printing report but it do not run report & nothing happens.

I am using code :
On Codeunit :-
>> SalesInvoiceHeaderReport.InitializeVariablesFunction('103001');

On Report :- (On "InitializeVariablesFunction" (ReportID) )

>> "Sales Invoice Header".RESET;
>> "Sales Invoice Header".SETRANGE("No.",ReportID);
>> REPORT.RUNMODAL(206,FALSE,TRUE,"Sales Invoice Header");

I pass report ID from codeunit and then put setrange.
>>Reports run fine when I use -> REPORT.RUNMODAL(206,TRUE,TRUE,"Sales Invoice Header");

>>Reports does not run fine when I use -> REPORT.RUNMODAL(206,FALSE,TRUE,"Sales Invoice Header");

Answers

  • Options
    atpiyushatpiyush Member Posts: 12
    I am able to save the report as PDF, send as attachment in email but not able to run it while the "Request Page" parameter is false for "REPORT.RUNMODAL" function.
    Please suggest me a way around.
    Requirement is that the specific report should be run during the posting routine of a particular record.
  • Options
    JuhlJuhl Member Posts: 724
    Do you run the Report from within the Report???

    Just filter the record in the codeunit and pass it with the Report.Run Call. No need for the variable function, as I see it.
    Follow me on my blog juhl.blog
  • Options
    atpiyushatpiyush Member Posts: 12
    Hi Juhl,
    Yes I'm running report from within the report.

    I am not able to filter record from codeunit as when I run it from codeunit, I don't know why but filter gets clear automatically.
  • Options
    JuhlJuhl Member Posts: 724
    Don't run something from itself.

    If filters don't work. Then call the report from its variable after calling the function.
    Variable.run; (not report.run)
    Follow me on my blog juhl.blog
  • Options
    atpiyushatpiyush Member Posts: 12
    edited 2017-09-12
    If I call the report using report object variable, I am not able to run the report if I make the 'Request Page' property set to false using code.
    Report does not show output and go for default printer option set in your local PC.
    For example, default printer in my PC is local printer, so running report it start printing and does not show output on the RTC window.
  • Options
    JuhlJuhl Member Posts: 724
    SalesInvoiceHeaderReport.InitializeVariablesFunction('103001');
    SalesInvoiceHeaderReport.RUN;

    OR

    SalesInvoiceHeaderReport.GET('103001');
    REPORT.RUN(206, FALSE, TRUE, SalesInvoiceHeaderReport);

    Both should work, unless you clear the filter in Report.
    Follow me on my blog juhl.blog
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi,

    Why can't you use much simpler construction in your codeunit, like below, and get rid of InitializeVariablesFunction from the report ?
    SalesInvoiceHeader.GET('103001');
    SalesInvoiceHeader.SETRECFILTER; //without this it will print everyting.
    REPORT.RUNMODAL(206, FALSE, TRUE, SalesInvoiceHeader);
    

    Slawek





    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    atpiyushatpiyush Member Posts: 12
    Hi Slawek,

    I tried your solution as well. It again go to print and does not show output on RTC.
  • Options
    atpiyushatpiyush Member Posts: 12
    Problem is that it is not showing output on RTC if I use any code samples above suggested by you guys.
    On the other hand, if I make "Request Window" property set to true, everything works fine.
    But I don't need request window as this report will be running at the time of posting a record.
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    REPORT.RUNMODAL(.., FALSE, TRUE,...) is not supposed to show any output on the RTC. It prints directly to the printer.

    If you want to have a preview you have to use REPORT.RUNMODAL(.., TRUE, TRUE,...) or REPORT.RUN(.., TRUE, TRUE,...)

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.