Blog, CRM Extensions, Ultimate Workflow Toolkit

UWT: Email Invoice in PDF format

It became a typical scenario – Email Quote or Invoice to customer in PDF format. When you’re on premise – it’s not a big problem – develop report, publish it to CRM, publish it to Reporting Services and use Reporting Services to render report in PDF format. But what to do when you’re online? One of new steps introduced in latest version of Ultimate Workflow Toolkit helps you to automate this process.

I used CloudConvert cloud service for this purpose (please don’t consider this as an advertisement – I don’t get any royalties). So to use this step you will have to subscribe for some plan with CloudConvert. If you do less than 25 conversions per day then you can go with “Free Plan”. I will not provide registration details in this post.

As a first step add generation of “Invoice Template” to Word using OOB functionality – “Perform Action” step – “SetWordTemplate”:

After that add “UWT: Annotation: Convert File” step and configure it:

Set reference to source record, enter the name of document that was generated on the previous step and enter name of file that you want to get as an output – in my case I wanted Word Document to be converted to PDF. Also you can define if you want to store converted document or replace original one using “Replace Original File” radiobutton.

On the next step create email without sending it.

After that add “UWT: Email: Attach Notes from Record to Email and Send” step and configure it:

Set “Record Reference” to reference of record word template was generated for, add a filter that includes filter by filename, set “Send Email” to “True” and populate Email lookup with email you created previously.

Save and activate workflow. Let’s see it in action:

22 Comments on “UWT: Email Invoice in PDF format

  1. Hi,
    I am trying to use Email Invoice in PDF format workflow, but it is not attaching the document. It only sends an email.
    Can you please help me on this.

    Thanks

      1. Hi Andrew,
        Thanks for you response.

        Firstly, I am getting this error when i am converting the document which is your second step:

        Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): UltimateWorkflowToolkit.CoreOperations.Annotation.ConvertFile: System.NullReferenceException: Object reference not set to an instance of an object.
        at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
        at Microsoft.Crm.Sandbox.SandboxCodeUnit.c__DisplayClass24_0.b__0()
        at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
        at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
        at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)
        at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)
        at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
        — End stack trace —

        Secondly, i can’t attach the screen shot over here.
        I am explaining what i am doing:
        1- Created the workflow on invoice level,when invoice generated
        2- Action: SetWordTemplate Entity -> i have invoice template, (Invoice1.docx)attached
        -> Target : Invoice
        3- UWT: Annotation:Convert file -> Resulting file name: Invoice.pdf
        -> Replacing Orignal file: True
        -> Record Reference: RecordUrl(Invoice)
        -> Currentfilename: Invoice1.docx

        Right now, it’s not going forward from this step: it gives the above mentioned error.

        4- Create Email -> From and To mentioned but without body
        5- UWT -> Email Attach Notes From Record to Email and Send -> Record reference : RecordURL(Invoice_
        -> Document filter:
        -> Send Email = True
        -> Email : {Email Message(Create (Email)}
        Much Appreciated.
        I am struggling to send the email with attachments, but.

        Thanks.

        1. Hi,

          Thanks Andrew. Much appreciated.

          It’s working now. I tried below lines to attach two documents, but i got an error: Changes to attachments for an email in pending or sending status is not allowed.

          UWT: Email:Attach Notes from Record to Email and Send
          UWT: Email:Attach Notes from Record to Email and Send

          Failed. You do not have enough privileges to access the Microsoft Dynamics 365 object or perform the requested operation. For more information, contact your Microsoft Dynamics 365 administrator. Started On: 1/31/2019 4:54 PM

  2. Hi,

    I’m trying to convert an attachment from a word doc to HTML, and I get the following error –

    File CVTest.docx is not available for current record

    Any ideas?

    Thanks!

    1. Hello Cameron,
      Can you please post the screenshot of the Convert Document step and screenshot that shows that this document really exists under the record?
      Andrew

        1. Cameron,
          You can store screenshots somewhere (onedrive or so) and put links here.
          Andrew

      1. Thanks Andrew,

        I’ve changes it to the following –

        https://docs.zoho.com/file/g8kn56d0c236c21b249e6a41cd084d74bffd4

        But receive this error –

        An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): UltimateWorkflowToolkit.CoreOperations.Annotation.ConvertFile: System.NullReferenceException: Object reference not set to an instance of an object.

        Plugin Trace:

        [UltimateWorkflowToolkit.CoreOperations: UltimateWorkflowToolkit.CoreOperations.Annotation.ConvertFile]
        [UWT: Annotation: Convert File]

        Value of ‘Resulting File Name’ attribute equals to test.html
        Value of ‘Replace Original File’ attribute equals to True
        Value of ‘Record Reference’ attribute equals to https://hwqdev.crm6.dynamics.com:443/main.aspx?etc=10428&id=f5e3645b-49c5-e911-a97c-000d3ad1cc81&histKey=867065092&newWindow=true&pagetype=entityrecord
        Value of ‘Current File Name’ attribute equals to CVTest.docx
        Value of ‘Throw an Exception on Error’ attribute equals to True

        Error Message:

        Unhandled exception:
        Exception type: Microsoft.Crm.CrmException
        Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): UltimateWorkflowToolkit.CoreOperations.Annotation.ConvertFile: System.NullReferenceException: Object reference not set to an instance of an object.
        at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
        at Microsoft.Crm.Sandbox.SandboxCodeUnit.c__DisplayClass24_0.b__0()
        at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
        at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
        at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)
        at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)
        at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
        — End stack trace —

        1. Thanks Andrew that’s worked a treat!

          With the CloudConvert is it possible to get by on the free account? I imagine our volumes will be pretty low.

  3. Hi Andrew,

    I’ve been using your workflows to convert word docs to HTML, and has been working great.

    Do you have a plugin version of this?

    Thanks.

  4. Hey Andrew,

    I followed the instructions but it seems I get an error message.

    Plugin Trace:

    [UltimateWorkflowToolkit.CoreOperations: UltimateWorkflowToolkit.CoreOperations.Annotation.ConvertFile]
    [UWT: Annotation: Convert File]

    Error Message:

    Unhandled Exception: Microsoft.Crm.CrmException: System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2B3888C1
    at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
    at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

    I have the API Key in our CRM, so is there something else I’m missing?

    1. Hello Michael,
      Thanks for using my toolkit. Can you please provide screenshot of the step from the workflow (I know it’s not possible to put screenshots here but you can host it somewhere and drop a url here).
      Thanks,
      Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.