Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

InstantiateTemplate doesn't work in Power Automate

(2) ShareShare
ReportReport
Posted on by 5

I'm trying to run the common data service (current environment) unbound action "instantiatetemplate".

When I do though I get the following error:

The API 'commondataserviceforapps' returned an invalid response for workflow operation 'Perform_an_unbound_action' of type 'OpenApiConnection'. Error details: 'The API operation 'PerformUnboundAction' requires the property 'body' to be of type 'Array' but is of type 'Object'.'

0363.pastedimage1615594332658v1.png

Any ideas on what is going wrong, or how to fix this?

  • Suggested answer
    kneely-STL Profile Picture
    10 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    maybe Microsoft changed the output but I do not get this error message and am able to use the output of the "Perform an Unbound Action" to populate the email I am creating in this flow. instantiatetemplate has an output that is the email message body with the template parts filled in.  NOTE: instantiatetemplate DOES NOT CREATE THE EMAIL YOU HAVE TO DO THIS.

    The output body for me looks something like this:
    pastedimage1670446721096v2.png

    Here's how it did it for a lead email template using the "Perform an Unbound Action" with  instantiatetemplate:

    pastedimage1670446435391v1.png

    Then I follow with a compose to get the 'description' returned from the "Perform an Unbound Action"

    body('Create_Template_Message_from_Lead_Details_(InstantiateTemplate)')['value']?[0]?['description']

    and the subject since the subject can have parts from the template:

    body('Create_Template_Message_from_Lead_Details_(InstantiateTemplate)')['value']?[0]?['subject']
    I hope this helps someone out there
  • Suggested answer
    dalsier Profile Picture
    10 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    I wrote a plugin wrapping the instantiate template action functionality and parsed the result into a string.

    The c# code:

        public class InstantiateTemplateWrapper : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                // Obtain the tracing service
                ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
                // Obtain the execution context from the service provider.  
                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                // The InputParameters collection contains all the data passed in the message request.  
                if (context.InputParameters.Contains("TemplateId") &&
                    context.InputParameters.Contains("ObjectId") &&
                    context.InputParameters.Contains("ObjectType"))
                {
    
                    // Obtain the organization service reference which you will need for  
                    // web service calls.  
                    IOrganizationServiceFactory serviceFactory =
                        (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
                    var templateId = Guid.Parse(context.InputParameters["TemplateId"].ToString());
                    var objectId = Guid.Parse(context.InputParameters["ObjectId"].ToString());
                    var objectType = context.InputParameters["ObjectType"].ToString();
    
                    var instTemplateReq = new InstantiateTemplateRequest
                    {
                        TemplateId = templateId,
                        ObjectId = objectId,
                        ObjectType = objectType
                    };
    
                    var instTemplateResp = (InstantiateTemplateResponse)service.Execute(instTemplateReq);
                    var email = instTemplateResp.EntityCollection.Entities.FirstOrDefault();
                    if (email != null)
                    {
                        var result = new InstantiateTemplateResult
                        {
                            Subject = email.GetAttributeValue("subject"),
                            Description = email.GetAttributeValue("description")
                        };
    
                        context.OutputParameters["JsonResult"] =
                            JsonHelpers.Serialize(result);
                    }
    
                }
            }
        }
    
        [DataContract]
        public class InstantiateTemplateResult
        {
            [DataMember]
            public string Subject { get; set; }
            [DataMember]
            public string Description { get; set; }
        }

    I registered the above plugin, you can follow these steps to accomplish so: /tutorial-write-plug-in

    I created an action InstantiatePluginPlus with the following parameters:

    Input:

    • TemplateId: Guid
    • ObjectId: Guid
    • ObjectType: string

    Output:

    • JsonResult: string

    Here you can find how to create actions: create custom actions

    I linked my plugin with my action, you can find the steps here: link plugin with action

    And finally I called my custom action from my power automate flow:

    8475.pastedimage1626358426861v1.png

  • Erdi Profile Picture
    15 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    Hi Mehdi El Emri,

    Can you explain how you could do it?

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: InstantiateTemplate doesn't work in Power Automate

    Hi 

    Unfortunately, the CDS connector doesn't support actions that return a collection. I created my own connector to call the "InstatiateTemplate" action: 

    pastedimage1616706231455v1.png



    pastedimage1616706895639v1.png

  • Jeremy3 Profile Picture
    5 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    I haven't been able to resolve this issue yet. I haven't tried for a workaround yet, but my first inclination is to just keep the email template as a variable in Power Automate and use string replace steps to update the variable to use as the email body. Not a great solution, but the only one I've thought of to this point.

  • April Collier Profile Picture
    21 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    I am having this exact same issue. Were you able to resolve your issue or come up with a workaround?

  • Jeremy3 Profile Picture
    5 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    Steps to get to the failure I'm seeing:

    1. Create a new step within a Power Automate flow

    2. Select the "Common Data Service (Current Environment)" connector

    3. Select the "Perform an unbound action" action

    4. For Action Name select "InstantiateTemplate"

        a. Note, this is a action that is available for this connector + action by default and is not an action I created unique to my CRM

    5. Set TemplateId/Object Type/ObjectId

    6. Run flow and notice failure mentioned in original question

    Let me know if any other information would be helpful in debugging or if there is any area I can do a better job clarifying.

  • necsa Profile Picture
    3,455 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    Please share more information

  • Jeremy3 Profile Picture
    5 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    The article you linked doesn't help me as instantiatetemplate is not an action I created so I can't control the output like mentioned.

  • necsa Profile Picture
    3,455 on at
    RE: InstantiateTemplate doesn't work in Power Automate

    Hi,

    please check the following link

    debajmecrm.com/.../

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans