Calling SetWordTemplate from custom ribbon button in Dynamics 365

Check the other articles of this series

Let us continue our previous post and this time instead of calling SetWordTemplate action / request from a workflow, we will call it using a custom ribbon button.

If we try calling the action directly using
method from a custom ribbon button, we will get the below error “Resource not found for the segment ‘SetWordTempalte’

Source Code: –

function CallAction()

var parameters = {};

var selectedTemplate = {};
selectedTemplate["@odata.type"] = "Microsoft.Dynamics.CRM.documenttemplate";
selectedTemplate["documenttemplateid@odata.bind"] = "/documenttemplates(4853247F-AD72-EA11-A811-000D3A31EEC)";

var target = {};
target["@odata.type"] = "Microsoft.Dynamics.CRM.lead";
target["leadid@odata.bind"] = "/leads(2fa01d2d-7332-e611-80e5-5065f38b31c1)";

parameters.SelectedTemplate = selectedTemplate;
parameters.Target = target;
var setWordTemplateRequest = {
SelectedTemplate: parameters.SelectedTemplate,
Target: parameters.Target,

getMetadata: function() {
return {
boundParameter: null,
parameterTypes: {
"SelectedTemplate": {
"typeName": "mscrm.documenttemplate",
"structuralProperty": 5
"Target": {
"typeName": "mscrm.lead",
"structuralProperty": 5
operationType: 0,
operationName: "WinOpportunity"
function success(result) {
if (result.ok) {

function(error) {


As a workaround, we can define a custom action and add the Perform Action step with SetWordTemplate step to it.

Source Code: –

function CallSetWordTemplateAction(primaryControl) {

var formContext = primaryControl;
var leadid =; 

var target = {};
target.entityType = "lead"; = leadid; 

var req = {};
req.entity = target;
req.getMetadata = function () {
return {
boundParameter: "entity",
parameterTypes: {
"entity": {
typeName: "mscrm.lead",
structuralProperty: 5
operationType: 0,
operationName: "pcfpre_CreateDocumentAction"
function (data) {
var e = data; 

function (error) { 

var errMsg = error.message;

Another option is to use the Process.js library

The Ribbon Button

Ribbon button definition

Dynamics 365 for Phone \ Tablet


Source Code: –

function createWordDocument(primaryControl) {

var formContext = primaryControl;

var leadid =;

key: "Target",
type: Process.Type.EntityReference,
value: new Process.EntityReference("lead", leadid)
key: "SelectedTemplate",
type: Process.Type.EntityReference,
value: new Process.EntityReference("documenttemplate", "{4853247F-AD72-EA11-A811-000D3A31EEC8}")

alert('Document created');

function (error, trace)


It internally makes the Soap call to SetWordTemplate Request.

Although we are able to attach the doc to notes, from mobile if we try to open it we will get the below error message


To get the document upload to work seamlessly either we need to use Windows 10 based tablets or we need to use out of the box SharePoint integration.

Hope it helps..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

3 thoughts on “Calling SetWordTemplate from custom ribbon button in Dynamics 365”

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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


Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog & Website of Paul Andrew

Technical Leadership Centred Around the Microsoft Data Platform

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform


Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions


Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM


Mail to for queries and suggestions

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM


Step into the world of a Dynamics 365 Consultant

Dianamics PCF Lady

Diana & Dynamics 365 & Power Platform

Sara Lagerquist

No Code Customization Concepts

%d bloggers like this: