Sending Two SSRS Reports on One Email

Hi,

We’ve created a function which sends an email with a copy of the Order Acknowledgement SSRS report.

We have a second email which sends another sales order-related BAQ report.

Is it possible to set up one email to be sent out with both SSRS reports attached? Has anyone been able to do this?

Thanks kindly for any help.

1 Like

Yes. I’ll get back to you with an example.

1 Like

You have to run them, and email them yourself.
Here is an example.

This uses the Email Library I made which is available here, which just makes handling the attachments slightly easier. You don’t have to use the library, just go look at it so you can see how attachments work.
Email Library

In this example, I just ran the same type of report twice, instead of running some other type of report.

//using Erp.Tablesets;
//using Newtonsoft.Json;

//ref: Assembly -> Newtonsoft.Json
//ref: Libraries -> EmailLibrary
//ref: Services -> ERP.Rpt.SalesOrderAck
//ref: Tables -> ICE.SysRptLst (Read Only)
//ref: Tables -> ICE.SysTask (Read Only)


Func<int, byte[]> GetASalesOrderPDF = (salesOrderNum) =>
{
    byte[] reportPDF = null;

    CallService<Erp.Contracts.SalesOrderAckSvcContract>(soa =>
    {
        string taskNote = Guid.NewGuid().ToString(); //Magic
    
        SalesOrderAckTableset salesOrderAckTS = soa.GetNewParameters();
        
        SalesOrderAckParamRow paramRow = salesOrderAckTS.SalesOrderAckParam.First();
        
        paramRow.OrderNum = salesOrderNum;
        paramRow.AgentID = "SystemTaskAgent";
        paramRow.AutoAction = "SSRSGENERATE";
        paramRow.ReportStyleNum = 2;
        paramRow.TaskNote = taskNote;
        
        soa.RunDirect(salesOrderAckTS);
        
        reportPDF = (from sysRpt in Db.SysRptLst
                              join sysTask in Db.SysTask on
                                new {sysRpt.Company, sysRpt.SysTaskNum} equals
                                new {sysTask.Company, sysTask.SysTaskNum}
                              where
                                sysTask.TaskNote == taskNote
                              select
                                sysRpt.RptData).FirstOrDefault();
                                
    });
    
    return reportPDF;
};


Dictionary<string, byte[]> dicReports = new Dictionary<string, byte[]>();

int salesOrder1 = 263482;
int salesOrder2 = 263485;

dicReports.Add($"Report_{salesOrder1}.pdf", GetASalesOrderPDF(salesOrder1));
dicReports.Add($"Report_{salesOrder2}.pdf", GetASalesOrderPDF(salesOrder2));

string jsonDicReports = JsonConvert.SerializeObject(dicReports);

string fromEmail = "noreply@nope.com";
string toEmail = "me@nope.com";


this.EfxLib.EmailLibrary.Email(fromEmail, toEmail, "Test 2 Report Attachments", "Hello, here are two reports", jsonDicReports, false, false, "", "", "", "", "");

Edit: BTW, I’m working on a library now to make a lot of this easier.

5 Likes

As always great work @klincecum !

@ZanebK , what details are included within you BAQ report , is it something g that could be consolidated into the SSRS sales order acknowledge report ?

Other that you could build your own email to fire out of a BPM, use some nice html format and stuff and build in the contents of the both report that way.

2 Likes

Better yet, combine my method with @ridgea 's method, and have nice looking html email with attachments :tada:

1 Like

@klincecum great shout !

Fx Yes GIF by Atlanta

Thanks a lot both! Really appreciate it. I’ll try out the suggestions in the next couple of days and report back.

1 Like

You are a blessing man.

Dear @klincecum ,

Thanks for the perfect code block. I am trying to reproduce the same and facing below errors. Could you please help me on this?

1 Like

@klincecum - I think the issue is because of Required Transaction check box in Function maintenance. I have unchecked it and tried. It’s working cool. Thank you very much.

1 Like

Bingo Bango.

Gabriel Iglesias Finger Guns GIF by NETFLIX

2 Likes