4 Replies Latest reply on Jan 14, 2019 4:33 AM by lgtandi

    Create pdf document or report from workflow

    maba Apprentice

      Hello everyone,

       

      We have the following scenario:

       

      An end user opens a request offering and fills out a longer form. Several tasks are created via the workflow and various data is transferred to another system via a Web service. My question is if it is possible to create a document (in the best case a PDF file) with the service request parameters from the workflow. (Like a kind of report). This document should then also be sent via the workflow to a specific recipient by email. The use case requires that it must be a document and not just an email with all service request parameters. Can someone help here or has an idea whether such a thing is possible?

       

      Thank you very much

      Marcel

        • 1. Re: Create pdf document or report from workflow
          lgtandi Specialist

          I have solved a similar problem as follows:

          • Implement an Ivanti report that has the service request number (or record id) as aparameter and then displays the information of this service request as required.
          • Define a powershell script that invokes the report, renders it as required (e.g. as PDF) and then stores the output as attachment of the service request (or some kind of "helper" child object).
          • You could then invoke a "Run program" quick action from your workflow to invoke this powershell script.
          • Afterwards, you could invoke another "Send email" quick action within the workflow. Alternatively, you could send the email from the powershell script if you provide the recipient address as parameter to the powershell script.

           

          Hope this helps

          AnDi

          1 of 1 people found this helpful
          • 2. Re: Create pdf document or report from workflow
            maba Apprentice

            Hi AnDi,

             

            Thanks for your answer. That sounds very interesting.

            We haven't done much with "Run Program" yet. Maybe you can describe in more detail how the Powershell script can look like or where it has to be started.

            Furthermore it would be interesting how I can save it as an attachment to the ServiceRequest.

            I would be very grateful if you could explain this a little bit more, how you implemented this solution.

             

            Many Thanks

            Marcel

            • 3. Re: Create pdf document or report from workflow
              lgtandi Specialist

              Here is the powershell script we have developed to create a specific report as attachment of a specified object (prerequisite is of course, that an "Attachment" relationship is defined for the object):

               

              #<Header #############################################################################################################################################################

              # Author: Andreas Dittrich

              # Description: This script renders a specified Ivanti report and adds the result as attachment to a specified Ivanti object

              # using the Ivanti Integration Web Service.

              # Parameters:

              # reportServer Mandatory the URL to the report server that shall execute the report.

              # reportName Mandatory the relative path name of the report to be run.

              # reportFormat Optional (default: PDF) the format in which the report shall be exported

              # reportParams Optional any parameters to be provided to the report in Powershell hashtable notation.

              # tenant Mandatory the Ivanti tenant (as required by the "Connect" method of the Ivanti Web Integration Service)

              # userName Mandatory the name of an Ivanti user (as required by the "Connect' method of the Ivanti Web Integration Service)

              # password Mandatory the password of the Ivanti user (as required by the "Connect' method of the Ivanti Web Integration Service)

              # userRole Optional (default: Admin) the role of the Ivanti user (as required by the "Connect' method of the Ivanti Web Integration Service)

              # parentObjType Mandatory the type of business object (in Ivanti object reference notation) to which the created report shall be linked,

              # parentObjRecID Mandatory the record identifier of the business object to which the created report shall be linked.

              # attachmentName Mandatory the name under which the created report shall be stored.

              #

              # History:

              # 13.11.2018      uadi    v1.0 Initial version

              #

              #>Header #############################################################################################################################################################

               

               

              Param(

                  [Parameter(Mandatory=$true, HelpMessage='The URL to the report server that shall execute the report.')]

                  [string]$reportServer,

               

               

                  [Parameter(Mandatory=$true, HelpMessage='The relative path name of the report to be run.')]

                  [string]$reportName,

               

               

                  [Parameter(Mandatory=$false, HelpMessage='The format in which the report shall be exported(default: "PDF").')]

                  [ValidateSet('PDF', 'Word', 'Excel', 'CSV')]

                  [string]$reportFormat = 'PDF',

               

               

                  [Parameter(Mandatory=$false, HelpMessage='Any parameters to be provided to the report in Powershell hashtable notation.')]

                  [hashtable][email protected]{},

               

                  [Parameter(Mandatory=$true, HelpMessage='The Ivanti tenant to use')]

                  [string]$tenant,

               

               

                  [Parameter(Mandatory=$true, HelpMessage='The Ivanti login ID to use for the creation of the attachment (default: "InternalServices").')]

                  [string]$userName,

               

               

                  [Parameter(Mandatory=$true, HelpMessage='The password of the specified Ivanti user.')]

                  [string]$password,

               

               

                  [Parameter(Mandatory=$false, HelpMessage='The role that the user logs in (default: "Admin").')]

                  [string]$userRole = 'Admin',

               

               

                  [Parameter(Mandatory=$true, HelpMessage='The type of the business object (in Ivanti object reference notation) to which the created report shall be linked.')]

                  [string]$parentObjType,

                 

                  [Parameter(Mandatory=$true, HelpMessage='The record identifier of the business object to which the created report shall be linked.')]

                  [string]$parentObjRecId,

               

               

                  [Parameter(Mandatory=$true, HelpMessage='The name of the created attachment.')]

                  [string]$attachmentName

              )

               

               

              try {

              Add-Type -AssemblyName 'Microsoft.ReportViewer.WinForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'

               

              $rv = New-Object Microsoft.Reporting.WinForms.ReportViewer

              $rv.ProcessingMode = "Remote"

              $rv.ShowParameterPrompts = $false

                  $rv.ShowCredentialPrompts = $false

              $rv.ServerReport.ReportServerURL = $reportServer

              $rv.ServerReport.ReportPath = $reportName

               

               

              # Create the array of report parameters

              $params = New-Object 'Microsoft.Reporting.Winforms.ReportParameter[]' $reportParams.Count

              $i = 0

              foreach ($p in $reportParams.GetEnumerator()) {

              $params[$i] = New-Object Microsoft.Reporting.WinForms.ReportParameter($p.Name, $p.Value, $false)

              $i++

              }

               

               

                 # Set the report parameters

              $rv.ServerReport.SetParameters($params)

              $rv.RefreshReport()

              $rv.ServerReport.Refresh()

               

              # Set rendering parameters

              $mimeType = $null

              $encoding = $null

              $extension = $null

              $streamids = $null

              $warnings = $null

               

              # Render the SSRS report

              $bytes = $null

              $bytes = $rv.ServerReport.Render($reportFormat, $null, [ref] $mimetype, [ref] $encoding, [ref] $extension, [ref] $streamids, [ref] $warnings)

               

              # Ivanti connection information

              [string]$sessionKey = $null

              [string]$webServiceURI ="https://$tenant/HEAT/ServiceAPI/FRSHEATIntegration.asmx?wsdl"

               

               

                  # Create webservice reference object

                  $webproxy = New-WebServiceProxy -Uri $webServiceURI

               

                  # Connect to Ivanti

                  $connResponse = $webProxy.Connect($userName, $password, $tenant, $userRole)

                  if($connResponse.connectionStatus -match "Success"){

              $sessionKey = $connResponse.sessionKey

               

              # Create and set attachment parameter

              $attachmentCommandDataType = ($webProxy.GetType().namespace + '.ObjectAttachmentCommandData')

              $attachment = New-Object $attachmentCommandDataType

              $attachment.ObjectType = $parentObjType

              $attachment.ObjectId = $parentObjRecID

              $attachment.fileName = $attachmentName

              $attachment.fileData = $bytes

               

              # Create attachment

              $addAttachmentResponse = $webProxy.AddAttachment($sessionKey, $tenant, $attachment)

                  }

              else {

                      Write-Host $connResponse.exceptionReason

                  }

              }

              catch

              {

                  Write-Host $_

              }

              • 4. Re: Create pdf document or report from workflow
                lgtandi Specialist

                And here is an example of how to call this script via a "Run Program" quick action. This calls a report with name "Demo Report", exports it as PDF and creates an attachment for the service request the quick action is executed on.

                 

                 

                Note that we have defined in our environments to global constants ""IvantiReportServerURL" and "Tenant" that are referenced in the argument sections