Monday, 23 May 2016

00:31 - 2 comments

EXPORT REPORT AS PDF AND ATTACH THE SAME TO EMAIL ACTIVITY || MS CRM

Implementation Steps:
            Step 1: Create SSRS report.
            Step 2: Create Custom workflow to access those report.
            Step 3: Convert reports into PDF file.
            Step 4: Create On-Demand System workflow and then create Email Template.
            Step 5: Add the Custom workflow add give the create Email template as an input.

            Step 6: Activate the workflow and trigger it.

Step 1: Creating SSRS report 
·         From the Start Menu à Select All Programs à Microsoft SQL Server 2012 (or 2008) à Click on  à SQL Server Data Tools for Visual Studio 2012.
·         File à New à Project

             Select "Report Server Project" from the list à Enter a project Name and specify project Location à click OK

·         In Solution Explorer, right-click Reports, point to Add, and click New Item. If the Solution Explorer window is not visible, from the View menu, click Solution Explorer.
·         In the Add New Item window, click Report.


             In Name, type Reports.rdl and click Add

·         Report Designer opens and displays the new .rdl file in Design view.
Step 2: Deploying the Report in CRM
·           Deploying Report in CRM is quite an easy task like we use to SSRS reporting portal. Go to Module menu, Tools and Reports.


    
     Click on new Button in reports, a popup will open for new report.


Select “Existing report” from Report type drop down and select report and click on “save”, your report will be added to reports in CRM.



After add the Report in CRM.




·         From the Start Menu àSelect All Programs àMicrosoft Visual Studio (or 2008).
·         File àNew àProject. Select "Class Library" from the list àEnter a project Name and specify project Locationà click OK
·         In Solution Explorer, right-click Referencesà Add References then add the CRM references

·         In same way to add the Service Reference also.
·        Write a code to get the Report from CRM and convert that report as a PDF file.
      Add the below code to convert the PDF file.
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Workflow;
using System.Linq;
using System.Net;
using System.ServiceModel;
using Microsoft.Xrm.Client.Services;
using System.IO;


namespace CustomReport
{
public class Class1 : CodeActivity
{
[Input("E-Mail")]
[ReferenceTarget("email")]
public InArgument<EntityReference> Email { get; set; }

protected override void Execute(CodeActivityContext executionContext)
{
try
{
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

Guid accountId = context.PrimaryEntityId;
byte[] result = null;

ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = new NetworkCredential("USER NAME", "PASSWORD", "DOMAIN");
rs.Url = "http://(REPORT SERVER IP ADDRESS)/ReportServer/ReportExecution2005.asmx";

string reportPath = "/Account Details";           
string format = "PDF";
string historyID = null;
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);

String SessionId = rs.ExecutionHeaderValue.ExecutionID;

result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

                //Create email activity
                Entity attachment = new Entity("activitymimeattachment");
                attachment["objectid"] = Email.Get<EntityReference>(executionContext);
                attachment["objecttypecode"] = "email";
                attachment["filename"] =
                attachment["subject"] = "Reports.pdf";
                attachment["body"] = System.Convert.ToBase64String(result);

try
{
service.Create(attachment);
}
catch (Exception ex)
{
throw new Exception(string.Format("Error creating attachment - {0}", ex.Message));
}

try
{
service.Execute(new SendEmailRequest()
{
EmailId = Email.Get<EntityReference>(executionContext).Id,
IssueSend = true,
TrackingToken = string.Empty
});
}
catch (Exception ex)
{
throw new Exception(string.Format("Error sending email - {0}", ex.Message));
}

              
}
catch (Exception err)
{
throw new Exception("Exception"+err);
}
}
}
}

·         Build the solution and deploy the solution into CRM using plugin registration tool.

     Step 3: Create System Workflow:

·         From Microsoft Dynamics CRM à Select Setting àProcesses Click



·         Then Create give a valid Name and select type as workflow and choose which entity it should be trigger.
·         Add a new step as create record. Then click on set properties button.

Choose an Email and create an Email template


      In Email template give “Form” address, “To” address and body of the text, then Save and Close the Email template.
·         After that add the custom workflow.


Then click on “Set Properties”


           Give input as create Email then “Save and Close”
            After that activate the workflow.


Finally when we trigger the on demand workflow the Email will generate and it have the attachment of the Report as a PDF file. 

2 comments:

This comment has been removed by the author.

"I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
Read more here:
kim kardashian sex tape
porn sex video hd
mia khalifa sex video
sunny leone sexy movie"

Post a Comment