Using Action to trigger Plugin in CRM 2013\2015

Hi,

We recently had a requirement to call Plugin on execute of an Action.

To implement this,

We created a blank Action named Trigger Plugin for custom entity named Security Entity.

Open Plugin Registration Tool and connect to the Org and we will have our action available there as message for our Plugin Step

We can execute our Action from C# and Jscript which in turns will call our Plugin.

C# Code:

Jscript Code:


var xml = "" +
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\"><a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\"><a:KeyValuePairOfstringanyType><b:key>Target</b:key><b:value i:type=\"a:EntityReference\"><a:Id>1c54dadd-f91b-e511-a5ca-c4346bacae20</a:Id><a:LogicalName>tk_securityentity</a:LogicalName><a:Name i:nil=\"true\"/></b:value></a:KeyValuePairOfstringanyType></a:Parameters><a:RequestId i:nil=\"true\"/><a:RequestName>new_TriggerPlugin</a:RequestName></request></Execute></s:Body></s:Envelope>" +
"";

var xmlHttpRequest = new XMLHttpRequest();

xmlHttpRequest.open("POST", Xrm.Page.context.getClientUrl() +"/XRMServices/2011/Organization.svc/web", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseText;
alert(resultXml);

Use the SoapLogger tool to get the Soap request

https://nishantrana.me/2014/08/27/updated-soaplogger-for-crm-2013-to-generate-javascript/

Hope it helps..

 


Author: Nishant Rana

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

2 thoughts on “Using Action to trigger Plugin in CRM 2013\2015”

Share your thoughts

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s