Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Ribbon Workbench button that creates a document using SetWordTemplate action Failed? An unexpected error occurred.

Posted on by 580

I'm attempting to create a custom button using the Ribbon Workbench that creates a document from our Word Document Templates. But it gives error. 

function GenerateDoc()
{
//alert("called");
//Fetch XML for Getting the ID of Document Template
var templateName = "Company Test V1";
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='documenttemplate'>"+
"<attribute name='documenttype' />"+
"<attribute name='name' />"+
"<attribute name='status' />"+
"<attribute name='modifiedon' />"+
"<attribute name='modifiedby' />"+
"<attribute name='description' />"+
"<order attribute='documenttype' descending='false' />"+
"<order attribute='name' descending='false' />"+
"<filter type='and'>" +
"<condition attribute='documenttype' operator='eq' value='2′ />" +
"<condition attribute='status' operator='eq' value='0′ />" +
"<condition attribute='name' operator='eq' value='" + templateName + "'/>" +
"</filter>" +
"</entity>"+
"</fetch>";
var docTemplateResults = XrmServiceToolkit.Soap.Fetch(fetchXml);
//If Template found
if (docTemplateResults.length > 0) {
debugger;
//Get the template Id
var templateId = docTemplateResults[0].attributes.documenttemplateid.value;
alert(templateId + " -- Id -- " + Xrm.Page.data.entity.getId());
// Call an Action

Process.callAction("SetWordTemplate",
[{
key: "Target",
type: Process.Type.EntityReference,
value: new Process.EntityReference("account", Xrm.Page.data.entity.getId())
},
{
key: "SelectedTemplate",
type: Process.Type.EntityReference,
value: new Process.EntityReference("documenttemplate", templateId)
}],
onWordDocumentGenerated,errorCallback
)

}

}
function onWordDocumentGenerated() {
alert("Document created!");
}
function errorCallback(error, trace) {
//Notify.remove("myProcessing");
alert("Error: " + error, "ERROR", "myError");
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ribbon Workbench button that creates a document using SetWordTemplate action Failed? An unexpected error occurred.

    Did you ever get an answer for this? I am trying to do the same thing but in the on-prem CRM.

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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans