web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call Plugin from Custom Ribbon Button

(0) ShareShare
ReportReport
Posted on by

Hi,

I have done a plugin to do some manipulations in Quote page. Customer requirement is to create a custom button in Quote page and call my plugin while click on my custom button. I have created button with the help of RibbonWorkbench and I can able to make a javascript call. But I could not able to call my plugin. Anyone please guide me that how to register my plugin for newly created button in Quote form or call my plugin while click on custom button?

Thanks in advance. 

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    use Action wait a minute i will send a blog to you

  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    you can use a action and call the action in your button click that can internally call plugin.

    Find below post that shows  in detail how to call plugin using action

    nishantrana.me/.../using-action-to-trigger-plugin-in-crm-20132015

  • Community Member Profile Picture
    on at

    you have to create action in action step register you plugin

    and call it through js

    js code is

    // JavaScript source code

    function callthisfunction() {

       var ACTION_NAME = "myCustomAction"; // you custom action name

       var requestMain = "";

       requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

       requestMain += "  <s:Body>";

       requestMain += "    <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";

       requestMain += "      <request xmlns:a=\"schemas.microsoft.com/.../Contracts\">";

       requestMain += "        <a:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";

       requestMain += "        <a:RequestId i:nil=\"true\" />";

       requestMain += "        <a:RequestName>" + ACTION_NAME + "</a:RequestName>";

       requestMain += "      </request>";

       requestMain += "    </Execute>";

       requestMain += "  </s:Body>";

       requestMain += "</s:Envelope>";

       debugger;

       var url = getClientUrl() + "XRMServices/2011/Organization.svc/web";

       var xmlhttp = new XMLHttpRequest();

       xmlhttp.open("POST", url, true);

       xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");

       xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

       xmlhttp.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

       xmlhttp.onreadystatechange = function () { processActionCallingResponse(xmlhttp, getSuccessResponse, getErrorResponse); };

       xmlhttp.send(requestMain);

    }

    function processActionCallingResponse(req, successCallback, errorCallback) {

       debugger;

       if (req.readyState == 4)/*4 = Complete*/ {

           req.onreadystatechange = null;// Potential memory leak issue with IE

           if (req.status == 200)/*200 = OK*/ {

               successCallback();

           }

           else {

               errorCallback(req.responseXML);

           }

       }

    }

    function getClientUrl() {

       var strUrl = Xrm.Page.context.getClientUrl();

       if (strUrl.substr(strUrl.length - 1) != "/") {

           strUrl += "/";

       }

       return strUrl;

    }

    function getSuccessResponse() {

    }

    function getErrorResponse(responseXml) {

       debugger;

       if (responseXml != null &&

           responseXml.firstChild != null && responseXml.firstChild.firstChild != null) {

           try {

               var bodyNode = responseXml.firstChild.firstChild;

               //Retrieve the fault node

               for (var i = 0; i < bodyNode.childNodes.length; i++) {

                   var node = bodyNode.childNodes[i];

                   //NOTE: This comparison does not handle the case where the XML namespace changes

                   if ("s:Fault" == node.nodeName) {

                       for (var j = 0; j < node.childNodes.length; j++) {

                           var faultStringNode = node.childNodes[j];

                           if ("faultstring" == faultStringNode.nodeName) {

                               alert("Error while Copy Opportunity: " + faultStringNode.textContent);

                               break;

                           }

                       }

                       break;

                   }

               }

           } catch (e) {

               alert("Error");

           };

       } else {

           alert("Error");

       }

    }

  • Verified answer
    Abhishek Gupta Profile Picture
    2,003 on at

    Hi,

    I have implemented this concept long time back. you can go through my blog.

    crmposts.blogspot.in/.../calling-actions-through-java-script.html

    you will find a sample of JavaScript containing a complete XML format along with the call to soap service.

    two steps are require to do in JavaScript

    1) create JavaScript and create a soap envelop

    2) Call soap service

    create an action, you can send and receive response through parameter.

    Please mark my answer correct, if you find so.

    Thanks

    Abhishek

  • Community Member Profile Picture
    on at

    Thanks Chitrarasan. Let me try it and let you know.

  • Community Member Profile Picture
    on at

    Thanks for your reply Fawad Ali.

  • Community Member Profile Picture
    on at

    Hi Abhishek,

    I tried your method. I am not getting responseXml or error message. Here is my code.

    function callAction()

    {

    alert('I am in');

    var entityId = Xrm.Page.data.entity.getId();

    alert('entityId : ' + entityId );

    var entityName = Xrm.Page.data.entity.getEntityName();

    alert('entityName : ' + entityName );

    var requestName = "new_recalculateproductprice";

    alert("requestName : " + requestName);

    // 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:Parameters xmlns:b=\"schemas.datacontract.org/.../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:RequestId>";

       requestXML += "        <a:RequestName>"+requestName+"</a:RequestName>";

       requestXML += "      </request>";

       requestXML += "    </Execute>";

       requestXML += "  </s:Body>";

       requestXML += "</s:Envelope>";*/

    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:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";

       requestXML += "        </a:Parameters>";

       requestXML += "        <a:RequestId i:nil=\"true\">";

       requestXML += "         </a:RequestId>";

       requestXML += "        <a:RequestName>"+requestName+"</a:RequestName>";

       requestXML += "      </request>";

       requestXML += "    </Execute>";

       requestXML += "  </s:Body>";

       requestXML += "</s:Envelope>";

    alert("requestXML : " + requestXML);

    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",     "schemas.microsoft.com/.../Execute&quot;);

       req.send(requestXML);

       //Get the Response from the CRM Execute method

       //var response = req.responseXML.xml;

       req.onerror = function (e) {

           alert(req.statusText);

       };

       if (req.status === 200) {

           alert(req.responseText);

       }

    }

    function GetClientUrl() {

    alert('i am in in client url');

       if (typeof Xrm.Page.context == "object") {

           clientUrl = Xrm.Page.context.getClientUrl();

       }

       var ServicePath = "/XRMServices/2011/Organization.svc/web";

    alert("ServicePath : " + ServicePath);

       return clientUrl + ServicePath;

    }

  • Community Member Profile Picture
    on at

    Hi Fawad Ali,

    I tried your code too. But no luck. Here is my code based on your suggestion. Kindly check it and let me know your comments.

    function callAction() {

    alert("hello from action");

    var entityId = Xrm.Page.data.entity.getId();

    alert('entityId : ' + entityId );

    var entityName = Xrm.Page.data.entity.getEntityName();

    alert('entityName : ' + entityName );

    var requestName = "new_recalculateproductprice";

    alert("requestName : " + requestName);

      var ACTION_NAME = "new_recalculateproductprice"; // you custom action name

      var requestMain = "";

      requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

      requestMain += "  <s:Body>";

      requestMain += "    <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";

      requestMain += "      <request xmlns:a=\"schemas.microsoft.com/.../Contracts\">";

      requestMain += "        <a:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\"><a:KeyValuePairOfstringanyType><b:key>Target</b:key><b:value i:type=\"a:EntityReference\"><a:Id>" + entityId + "</a:Id><a:LogicalName>" + entityName + "</a:LogicalName><a:Name i:nil=\"true\"/></b:value></a:KeyValuePairOfstringanyType></a:Parameters>";

      requestMain += "        <a:RequestId i:nil=\"true\" />";

      requestMain += "        <a:RequestName>" + ACTION_NAME + "</a:RequestName>";

      requestMain += "      </request>";

      requestMain += "    </Execute>";

      requestMain += "  </s:Body>";

      requestMain += "</s:Envelope>";

      debugger;

    alert(requestMain);

      var url = getClientUrl() + "XRMServices/2011/Organization.svc/web";

    alert(url);

      var xmlhttp = new XMLHttpRequest();

      xmlhttp.open("POST", url, true);

      xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");

      xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

      xmlhttp.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

      xmlhttp.onreadystatechange = function () { processActionCallingResponse(xmlhttp, getSuccessResponse, getErrorResponse); };

      xmlhttp.send(requestMain);

    }

    function processActionCallingResponse(req, successCallback, errorCallback) {

      debugger;

      if (req.readyState == 4)/*4 = Complete*/ {

          req.onreadystatechange = null;// Potential memory leak issue with IE

          if (req.status == 200)/*200 = OK*/ {

              successCallback(req.responseXML);

          }

          else {

              //errorCallback(req.responseXML);

      errorCallback(req.responseText);

          }

      }

    }

    function getClientUrl() {

      var strUrl = Xrm.Page.context.getClientUrl();

      if (strUrl.substr(strUrl.length - 1) != "/") {

          strUrl += "/";

      }

      return strUrl;

    }

    function getSuccessResponse() {

    alert("Success Response : " + responseXml);

    }

    function getErrorResponse(responseXml) {

      debugger;

    alert("Error Response : " + responseXml);

    }

  • Community Member Profile Picture
    on at

    Hi Ganesamoorthy Pandian,

    first copy your plugin logic and make a custom workflow and paste that logic in custom workflow, means you have to register workflow not plugin.

    if you already done this.

    then create an action and "Add Step" your custom workflow.

    then call action "new_recalculateproductprice"

    we can also send argument  from web-resource to custom workflow. and return parameter from custom workflow to web-resource.

    this is a little tedious job so send me your dev org credential and your plugin code

    to my email "fawad14414@gmail.com" i will done it for you.

    thanks,

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Fawad Ali

    What do you mean by register workflow not plugin? May you explain little bit more.

    Thank you

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans