Views:

In this SwiftReports example we are going walk through the steps to create a Letter template by importing a saved template, and then generating the letter as part of a Power Automate Flow.

Prerequisites: 

  • Swift AI configured with your own API key
  • A sample Contact record, with an email address specified on the owning user
  • Download the SwiftReports_Sample_Letter_Template.json file (right-click, Save as…)

Generate Report

Update individual elements

Once the report is generated you may need to tweak various aspects to get it how you want.

For example, replace the image with your logo:

  • Click the image element
  • Copy your png/jpg logo image to your clipboard
  • Paste into the Image Source field - you will see a preview of the image shown in the designer

Preview your template at anytime

  • Use Preview with sample data option from the PDF menu in the top right (the Preview with a real record option can be used once the report has been saved)

Create a Swift Configuration

Swift Configurations allow you to specify output configurations that execute when the template is run. For this example we are going to create and attached the PDF output to an email.

  • From the Report Properties panel expand Swift Configuration and click + Add
  • Enter Email as the Configuration Name
  • Toggle the Output Actions switch on
  • Toggle off the Return PDF as output parameter option
  • Toggle on the Create Email & Attach option
  • For Subject enter: Welcome {{contact.fullname}}!
  • For Body enter: Please see the attached welcome letter.
  • For To:
    • Click +Add Recipient
    • Click into the text field with the Record GUID placeholder text
    • Click the Inject Expression button on the top of the modal dialog
      • Enter contactid into the Search fields... box
      • Expand the Primary Record > Contact node from the Source tab
      • Click on Contact, contact.contactid is added to the expression editor
      • Click the Apply button
    • Select contact from the dropdown selector
    •  
  • For Regarding Id enter: {{contact.contactid}}
  • For Regarding Entity enter: contact
  • For Filename enter: WelcomeLetter.pdf
  • Click the Apply button

Save the report

  • Select Save from the SwiftReports menu
  • Select the Solution you would like to save the template to
  • In the Display Name field type Letter Template
  • Click Save

Test Generation

Now that the report has been saved we can do a live Test Generation against a selected record.

  • Select the Preview with a real record option from the PDF menu in the top right
  • Click the ellipses (...) button beside the Record ID field
  • Select Contact in the Look for: field
  • Click the Results button in the top left to list the contact records
  • Select the record for your test
  • Click the Add button (or double-click the selected record above)
  • Select Email from the Swift Configuration
  • Click Generate PDF
  • The Generated PDF opens in a new tab
  • Also check your selected contact's timeline to see the draft email

Create Power Automate Flow

We make it very easy to generate a PDF from your template as a step in a Power Automate Flow.  In this example we are going to create an on-demand Flow that creates a PDF and attaches it to an email.

Find your template ID

  • From the SwiftReports menu select Properties
  • Copy the Template ID

Create the Flow

  • Go to https://make.powerautomate.com/
  • Click Create, then select Instant Cloud flow
  • For Flow name enter: Create SwiftReports Letter
  • Select When a row is selected (Microsoft Dataverse) for the trigger
  • Click Create
  • Click on the When a row is selected step and select the Contacts table

Unbound action step

  • Click the + button to add a step
  • Enter unbound in the search and click Perform an unbound action from the Microsoft Dataverse category
  • For Action Name find and select north52_N52SwiftReportsGeneratePDFAsync
  • Click the Show all button under Advanced parameters
  • For Item/SwiftConfiguration Enter Email
  • Click into Item/PrimaryRecordData and find and select Contact (unique identifier for the contact)
  • Paste the Template ID you copied above into the item/TemplateData parameter
  • Click Save

Test

  • Navigate to a Contact record in Dataverse
  • From the Flow menu select Create SwiftReports Letter, then Run Flow
  • Monitor the Flow
  • Once finished refresh the Timeline for the contact and see the newly created email with attached PDF letter!

 

Related Articles (1)