Home General

Export and Send multiple reports at once - Sample?

edited April 2010 in General
Hi Everyone

Reading through the Wiki relating to E-Mailing
(http://www.digital-metaphors.com:8080/Output/Email/Email_Fundementals) it
mentions the ability to Export and Send Multiple Reports at once via the use
of the TppEmail Object.

Where my query relates to - if you have multiple TppReport objects. If you
know the number of reports at time of execution you could add that many
TppReport Components to a form. But in the case where the number of Reports
is dynamic - im having a bit of a brain drain on how to implement that
properly.

Is there a basic sample app to illustrate how it work?

I love the product and have done some amazing things with it.

Thanks
Scott

Comments

  • edited April 2010
    Hi Scott,

    If you have multiple report objects on a form and want to send all of them
    in a single email, you could loop through each component on the form and add
    each TppReport to the TppEmail object using the AddReport routine.
    Something like the following...

    var
    lEmail: TppEmail;
    liIndex: Integer;
    begin

    lEmail := TppEmail.Create;

    for liIndex := 0 to Form1.ComponentCount - 1 do
    begin
    if Form1.Components[liIndex] is TppReport then
    lEmail.AddReport(TppReport(Form1.Components[liIndex]));
    end;

    lEmail.Send;


    If you need to send each report separately, you will also need to loop
    through each component but instead of creating a TppEmail object, you can
    simply call Report.SendMail for each TppReport object found.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2010
    Hi Nico

    Thanks for the response. The sample you provided is/can be used when you
    "know" how many TppReport components on a form. But are there multiple
    Pipelines on the Form - one for each TppReport Component - or are they using
    a shared Pipeline?

    Turning it around to something I am working on atm - one of my Clients wants
    to send an email containing variable amounts on invoices attached to an
    email. So I have been trying to figure out how to do it.

    So using the EmailExample.zip from the wiki, I had come up with the
    following rough code. All the Report Templates are stored in a SQL Database.

    var
    lEmail: TppEmail;
    liIndex : integer;
    lReport: TppReport;
    InvoiceType : TInvoiceType
    begin
    // Assume there is a TObjectList named InvoicesList, where each object
    has the following members
    //
    // InvoiceID
    // InvoiceType // As there are multiple types of Invoices that
    have different Reports
    //
    // Stored in TInvoiceType

    lEmail := TppEmail.Create;

    for liIndex := 0 to InvoiceList.Count - 1 do
    begin
    lReport := TppReport.Create(Self);
    lReport.DataPipeLine := ADOPipeLine;

    // Work out report named based upon
    TInvoiceType(InvoiceList[liIndex]).InvoiceType
    lReport.Template.DatabaseSettings.Name :=
    GetReportNameForInvoiceType(TInvoiceType(InvoiceList[liIndex]).InvoiceType);
    lReport.Template.LoadFromDatabase();

    // Add The Paramater to the report to filter on
    TInvoiceType(InvoiceList[liIndex]).InvoiceID

    lEmail.AddReport(lReport);
    end

    lEmail.Send();
    end;


    At this point, there is a Single ADOPipeLine. So where I am trying to figure
    out - can I get away with a single data pipleline and have "N" reports
    hooked to the data pipeline, or do I need to create additional ADOPipelines
    for each TppReport? I hope it all makes sense.

    Is this doable? Or am I going to need to setup separate Data Pipelines for
    each of the Reports?

    Thanks again
    Scott

  • edited April 2010
    Hi Scott,

    The Email objects process all reports in the list separately before sending
    the email. I believe that you should only need one Datapipeline (granted
    all reports use this pipeline). The easiest solution would to to keep the
    pipelines local to the templates using DADE.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.