July 4, 2015 10:35 AM
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:
</p>
<p>var xml = "" +<br />
"<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>" +<br />
"";</p>
<p>var xmlHttpRequest = new XMLHttpRequest();</p>
<p>xmlHttpRequest.open("POST", Xrm.Page.context.getClientUrl() +"/XRMServices/2011/Organization.svc/web", false);<br />
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");<br />
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");<br />
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");<br />
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);<br />
xmlHttpRequest.send(xml);</p>
<p>var resultXml = xmlHttpRequest.responseText;<br />
alert(resultXml);</p>
<p>
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..
Subscribe to get the latest posts sent to your email.
Posted by Nishant Rana
Categories: CRM, CRM 2013, CRM 2015
Tags: CRM 2013, CRM 2015, Microsoft Dynamics CRM
Mobile Site | Full Site
Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.
HTTP RESPONSE
————————————————–
http://www.w3.org/2003/05/soap-envelope:Sender
you are mickey mouse
-2147220891
OperationStatus
0
SubErrorCode
-2146233088
This is custom error message
2015-07-04T04:40:02.459002Z
[testPlugin: testPlugin.Class1]
[489d435e-bc21-e511-8c30-c4346bacae20: testPlugin.Class1: new_TriggerPlugin of tk_securityentity]
LikeLike
By Nishant Rana on July 4, 2015 at 10:41 AM
Reblogged this on CRM Practice.
LikeLike
By Vijay (Learning Techniques) on July 29, 2016 at 7:27 PM
Hi Rana , I Need to get action parameters data In plugin. I hv 5 input parameters i need to get those parameters daa in plugin…
Please sens me the codeb
LikeLike
By balugajjala on July 21, 2017 at 7:56 AM
Hi Nishant,
Created action & calling that action using c# plugin code, but no error is getting unable to do .
LikeLike
By Anonymous on August 23, 2017 at 11:21 AM
[…] https://nishantrana.me/2015/07/04/using-action-to-trigger-plugin-in-crm-20132015/ https://garethtuckercrm.com/2011/03/16/jscript-reference-for-microsoft-dynamics-crm-2011/ […]
LikeLike
By Useful Links Dynamics 365 – D365Notes on September 3, 2019 at 9:27 PM
Hi Nishant, I am new to CRM development and thanks for this post. how ever, where did you put the C# and JavaScript codes? How these C# and JavaScript component are integrated with CRM?
LikeLike
By Wei on February 19, 2020 at 8:13 PM
C# code you can use within a console app and JavaScript within Ribbon Button in most cases.
LikeLike
By Nishant Rana on February 20, 2020 at 2:37 PM