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