Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Call plugin from JavaScript in Dynamics CRM

Posted on by Microsoft Employee

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"
}

 

Categories:
  • LuHao Profile Picture
    LuHao 40,872 on at
    RE: Call plugin from JavaScript in Dynamics CRM

    Hi Anil,

    Thank you very much for sharing.  :)

    In addition, if you have other sharing, I recommend you post it to the Community Blog: community.dynamics.com/b

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans