Nishant Rana's Weblog


Home | Pages | Archives


Using Action to trigger Plugin in CRM 2013\2015

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

 

Advertisements

Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Posted by Nishant Rana

Categories: CRM, CRM 2013, CRM 2015

Tags: , ,

7 Responses to “Using Action to trigger Plugin in CRM 2013\2015”

  1. 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]

    Like

    By Nishant Rana on July 4, 2015 at 10:41 AM

  2. Reblogged this on CRM Practice.

    Like

    By Vijay (Learning Techniques) on July 29, 2016 at 7:27 PM

  3. 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

    Like

    By balugajjala on July 21, 2017 at 7:56 AM

  4. Hi Nishant,
    Created action & calling that action using c# plugin code, but no error is getting unable to do .

    Like

    By Anonymous on August 23, 2017 at 11:21 AM

  5. […] 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/ […]

    Like

    By Useful Links Dynamics 365 – D365Notes on September 3, 2019 at 9:27 PM

  6. 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?

    Like

    By Wei on February 19, 2020 at 8:13 PM

    1. C# code you can use within a console app and JavaScript within Ribbon Button in most cases.

      Like

      By Nishant Rana on February 20, 2020 at 2:37 PM

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.