1: Create an action
Go to Settings>Processes and click new to create a new process. Select category as action and click ok
2: Activate the action
It’s just a blank action with no arguments or steps. Click on Activate button to activate it. It’s a unique name. You can keep the name as per your need. This name will look as the message in the plugin registration tool to register a step upon.
3: Build the plugin
Write your plugin code as per your requirement
4: Register the plugin assembly and step
Register your plugin assembly and register your step on action unique name message.
Select the primary entity and stage and register the step.
5: JavaScript to Call action
On successful registration of plugin step, it’s the time to call your action using JavaScript.
//Function - Call a Plugin function CallaPlugin(actionName) { try{ // Creating the request XML for calling the Action var requestXML = "" requestXML += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">"; requestXML += " <s:Body>"; requestXML += " <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">"; requestXML += " <request xmlns:a=\"schemas.microsoft.com/.../Contracts\">"; requestXML += " <a:RequestId i:nil=\"true\" />"; requestXML += " <a:RequestName>" + actionName + "</a:RequestName>"; requestXML += " </request>"; requestXML += " </Execute>"; requestXML += " </s:Body>"; requestXML += "</s:Envelope>"; var req = new XMLHttpRequest(); req.open("POST", fnGetClientUrl(), false); req.setRequestHeader("Accept", "application/xml, text/xml, */*"); req.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute"); req.send(requestXML); //Get the Resonse from the CRM Execute method var response = req.responseXML.xml; if (req.status === 200) { alert("Plugin called successfully"); } else { alert("Problem in plugin call"); } } catch (err) { alert(err); } } //Get Client Url function GetClientUrl() { return Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web"
}