Search code examples
javascriptdynamics-crmdynamics-crm-2013dynamics-crm-2015dynamics-crm-2016

Plug-in not triggering on the Custom Message created using Actions in CRM 2016


I've created a ribbon button, a blank action(process) and a Plug-in. I'm calling the action (JavaScript) from the ribbon button which further needs to trigger the plug-in using the custom message. I'm able to call the action using the soap call but it's not triggering the plug-in that has been registered on that custom message. I've put in an alert in the bottom of the helper method which is popping out successfully however the plug-in cannot be triggered. Any help is appreciated....

function SendIOButtonActionCall() {
var entityId = Xrm.Page.data.entity.getId();
var entityName = Xrm.Page.data.entity.getEntityName();
var requestName = "vm_SendIOButton";
var OpportunityId = String(Xrm.Page.data.entity.getId());
ExecuteAction(entityId, entityName, requestName);
//window.location.reload(true);   
}

function ExecuteAction(entityId, entityName, requestName) {
    // Creating the request XML for calling the Action
var requestXML = ""
requestXML += "<s:envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestXML += "  <s:body>";
requestXML += "    <execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestXML += "      <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
requestXML += "        <a:parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestXML += "          <a:keyvaluepairofstringanytype>";
requestXML += "            <b:key>Target</b:key>";
requestXML += "            <b:value i:type=\"a:EntityReference\">";
requestXML += "              <a:id>" + entityId + "</a:id>";
requestXML += "              <a:logicalname>" + entityName + "</a:logicalname>";
requestXML += "              <a:name i:nil=\"true\">";
requestXML += "            </a:name></b:value>";
requestXML += "          </a:keyvaluepairofstringanytype>";
requestXML += "        </a:parameters>";
requestXML += "        <a:requestid i:nil=\"true\">";
requestXML += "        <a:requestname>" + requestName + "</a:requestname>";
requestXML += "      </a:requestid></request>";
requestXML += "    </execute>";
requestXML += "  </s:body>";
requestXML += "</s:envelope>";
var req = new XMLHttpRequest();
req.open("POST", GetClientUrl(), false)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestXML); 
alert("success");
//Get the Response from the CRM Execute method
//var response = req.responseXML.xml;
}

function GetClientUrl() {
if (typeof Xrm.Page.context == "object") {
    clientUrl = Xrm.Page.context.getClientUrl();
}
var ServicePath = "/XRMServices/2011/Organization.svc/web";
return clientUrl + ServicePath;
} 

Solution

  • Things to check:

    1. Validate your plugin step is enabled.
    2. Validate your plugin works
      1. Register your plugin step on a message like Update against some entity to see if you can get it to trigger.
      2. Add logging to the plugin to see if you can get it to log something
    3. Validate your action works by making it create a record.
    4. Use Fiddler to check if there are any errors returned in any of the traffic that the button generates.