Options

passing parameters to report - Analysis Report

kmkaotkmkaot Member Posts: 261
Hi,

I want pass parameters and Filters to report - Analysis Report.

Can anybody help me

I have from date and to date for filters

anayreport.SetFilters(NewDateFilter,NewItemBudgetFilter,NewLocationFilter,NewDim1Filter,NewDim2Filter,NewDim3Filter,NewSourceTypeFilter,NewSourceNoFilter)

I have values for Parameter

anayreport.SetParams(NewAnalysisArea,NewReportName,NewLineTemplateName,NewColumnTemplateName)

Will you give me advice

Warm Regards
Kris

Answers

  • Options
    lubostlubost Member Posts: 615
    Function SetParams probably exists in report. You have to copy function parameters to global vars in this function and use these vars in report where you need. I don't know recommend you more precice because I don't know your requirements.
  • Options
    kmkaotkmkaot Member Posts: 261
    I am planning to keep this report Job queue. In frequential period, it will run the report and send to the user in the email. So Date Frequency is dynamic i.e one month for example 01-oct-17 to 31-10-17.
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi Kris

    You have basically answered yourself.

    You already have defined variable anayreport, you call functions anayreport.SetParams(...) and anayreport.SetFilters(...) passing your values.

    You may want to call anayreport.SetCalendarSource() as well and pass relevant params too, and possibly anayreport.USEREQUESTPAGE()

    After than call anayreport.RUN or anayreport.RUNMODAL(..), or one of anayreport.SAVEAS* functions and NAV will print or save your report.

    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
    kmkaotkmkaot Member Posts: 261
    Please help me with the following code where is the mistake


    kemail:='kneni@hotmail.com';

    Tofile := 'dashboard.pdf';

    // Paremeters
    //
    CUSTOMR:=CUSTOMR::Customer;
    NewAnalysisArea:=NewAnalysisArea::Sales;
    NewReportName:='CUSTSALE';
    NewLineTemplateName:='MASOOD';
    NewColumnTemplateName:='SALES';


    FileName := TEMPORARYPATH + Tofile;
    fromdate := CALCDATE ('<CM-2M+1D>', TODAY-180);
    todate := CALCDATE('<CM>',CALCDATE('<-CM-1D>',TODAY));
    NewDateFilter:=FORMAT(fromdate)+'..'+FORMAT(todate);
    MESSAGE(NewDateFilter); ;

    anayreport.SetParams(NewAnalysisArea,NewReportName,NewLineTemplateName,NewColumnTemplateName);
    anayreport.SetFilters(NewDateFilter,'','','','','',CUSTOMR,'');

    Tofile := DownloadToClientFileName(FileName, Tofile);
    anayreport.SAVEASPDF(Tofile) ;
    MESSAGE('HERE');

    // Mail.NewMessage(ToAddresses ,CcAddresses,BccAddresses,Subject,Body,AttachFilename,ShowNewMailDialogOnSend)
    Mail.NewMessage(kemail, '' ,'' ,'Purchase Order from Shura' ,Ksub ,Tofile , TRUE);
    // << Show Outlook Dialog before sending mail
    Mail.Send;

    variables
    ==================
    Name DataType Subtype Length
    NewDateFilter Text
    NewAnalysisArea Option
    NewLineTemplateName Text
    NewColumnTemplateName Text
    CUSTOMR Option
    NewReportName Text
    kemail Text
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    ServerFileName := C419.ServerTempFileName('.pdf');
    ClientFileName := C419.ClientTempFileName('.pdf');
    
    // I'd guess that you would want to save the report into the pdf file first...
    anayreport.SAVEASPDF(ServerFileName) ;
    
    // ...and download it after ..
    C419.DownloadToFile(ServerFileName , ClientFileName); 
    
    //...and clean after yourself
    ERASE(ServerFileName);
    
    //later 
    Mail.NewMessage(...ClientFileName , TRUE);
    ERASE(ClientFileName); //...and clean this one too
    
    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
    kmkaotkmkaot Member Posts: 261
    My problem is how to pass parameters and Filters .

    I am getting this error

    Specify a filter for the Date Filter field in the Analysis Line table.
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    kmkaot wrote: »
    I am getting this error
    Specify a filter for the Date Filter field in the Analysis Line table.
    Good to know, you know.

    You have passed the fiters / parameters correctly. Unfortunately they are not used until you open the report with the Request Page.

    So instead of
    anayreport.SAVEASPDF(Tofile) ;
    
    you should use
    anayreport.USEREQUESTPAGE(TRUE);
    anayreport.RUN
    
    or
    anayreport.USEREQUESTPAGE(TRUE);
    anayreport.RUNMODAL
    

    If you want to use SAVEASPDF the report needs to be changed, you need to copy the code (possibly just a part of it) from OnOpenPage trigger into a separate function which would initialise internals vars, like the DateFilter one.

    For future - get familiar with the NAV Debugger - it will quickly become your best frind.

    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
    kmkaotkmkaot Member Posts: 261
    hI Slawek,

    IT IS REALLY FANTASTIC HELP. THANK YOU.
    NOW I AM STRUGGLING TO START JOB QUEUE. I PUT THIS CU IN JOB QUEUE.

    I AM TRY9NG SEND AUTOMATICALLY

    WARM REGARDS
    KRIS
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-10-19
    Job Queue will not work with Outlook based emailing. You need to changew your code to use SMTP mail codeunit, and update bits and pieces, like the pdf file downloading, as the SMPT emailing works on the server side and needs the attachment file to be available on the NST
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    kmkaotkmkaot Member Posts: 261
    Yes this is right. I will change code as you said

    Thanks
Sign In or Register to comment.