Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

help understanding pluging and what is possible

$
0
0

CRM 2011 on premisis & SQL2008R2

We currently import about 100 xml files from a third party into our CRM system on a daily basis into a custom entity. I have written a SSRS report that currently is manually executed for each new entry and the report is saved as a PDF and emailed out to our customers. I have been trying to write a plugin that would auto create the PDF files, but can not get it to work.

When a record is imported into the entity, I have a process that extracts parts of the data and creates a record in a monitoring entity

Question.

1. If a plugin is registered on 'create', will it be fired if the entity record is imported?

2. does anyone know of a step by step tutorial that i can follow.

The code below for my attempt at a plugin, causes the import to fail. The report is a simple report for testing and does not take any parameters ( well i need to walk before I run ) . Any help or suggestions would be appreciated

attempt at plugin

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.IO
Imports System.Web
Imports System.Web.Services
Imports System.Xml
Imports System.Xml.Serialization
Imports Crm2011_Plugins.ReportingService
Imports System.Web.Services.Protocols
Imports System.Diagnostics
Imports Microsoft.Xrm.Sdk


Namespace ARUDDPDFGenerator
    Public Class pluginAruddReports
        Implements IPlugin


        Public Sub Execute(serviceProvider As System.IServiceProvider) Implements Microsoft.Xrm.Sdk.IPlugin.Execute
            Dim context As IPluginExecutionContext = DirectCast(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
            If context.InputParameters.Contains("Target") AndAlso TypeOf context.InputParameters("Target") Is Entity Then
                Dim entity As Entity = DirectCast(context.InputParameters("Target"), Entity)
                'new_licence()
                'new_addacsreportsid()
                ' 290c9065-5742-e311-8565-00155d01d303}

                Dim rs As New ReportExecutionService()
                rs.Credentials = System.Net.CredentialCache.DefaultCredentials
                rs.Url = "http://xxxxxxxxx/reportserver/ReportExecution2005.asmx"

                ' Render arguments
                Dim result As Byte() = Nothing
                Dim reportPath As String = "/xxxxCRM_MSCRM/{290c9065-5742-e311-8565-00155d01d303}"
                Dim format As String = "PDF"
                Dim historyID As String = Nothing
                Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"


                ' Prepare report parameter.
                'Dim parameters(2) As ParameterValue

                'parameters(0) = New ParameterValue()
                'parameters(0).Name = "EmpID"
                'parameters(0).Value = "288"
                'parameters(1) = New ParameterValue()
                'parameters(1).Name = "ReportMonth"
                'parameters(1).Value = "6" ' June
                'parameters(2) = New ParameterValue()
                'parameters(2).Name = "ReportYear"
                'parameters(2).Value = "2004"

                Dim credentials As DataSourceCredentials() = Nothing
                Dim showHideToggle As String = Nothing
                Dim encoding As String = ""
                Dim mimeType As String = ""
                Dim warnings As Warning() = Nothing
                Dim reportHistoryParameters As ParameterValue() = Nothing
                Dim streamIDs As String() = Nothing

                Dim execInfo As New ExecutionInfo
                Dim execHeader As New ExecutionHeader()
                ' Dim SessionId As String
                Dim extension As String = ""

                rs.ExecutionHeaderValue = execHeader

                execInfo = rs.LoadReport(reportPath, historyID)


                Try
                    result = rs.Render(format, devInfo, extension, _
                       encoding, mimeType, warnings, streamIDs)

                    execInfo = rs.GetExecutionInfo()



                Catch e As SoapException
                    Throw New InvalidPluginExecutionException("Error generating ARUDD Report - " & e.Message.ToString)
                End Try

                ' Write the contents of the report to an MHTML file.
                Try
                    Dim stream As FileStream = File.Create("C:\REPORT TEST IGNORE\report.PDF", result.Length)
                    stream.Write(result, 0, result.Length)
                    stream.Close()
                Catch e As Exception
                    Throw New InvalidPluginExecutionException("Error generating ARUDD Report - " & e.Message.ToString)
                End Try




            End If
        End Sub
    End Class
End Namespace

 

 


Dont ask me .. i dont know


Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>