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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Use of Action in Plugin and JavaScript in Dynamics 365 (MS CRM)

(0) ShareShare
ReportReport
Posted on by 2

Hi,

Can someone give a real time example with the sample code for "how to use Action in java script" and "how to use Action in plugin" ? If possible just inbox me in the email id rath.amit86@gmail.com.

Thanks

Amit Kumar Rath

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Amit,

    I have done this type of work in past, we had the requirement of sending account to other portal on the custom button click on account.

    Step 1) Add the Custom button on Your entity form (In my case it was account)

    Step 2) Create a Action (action name = new_sendAccounttoPortal)

    Step 3) Write a java script code for calling action from it.

    Step 4) New message will be create in the plugin registration tool with the name "new_sendAccounttoPortal". with the help of this you can call plugin and do your job.

    Give me some time i will provide code also.

    Thanks,

    Shahbaaz

  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Amit, Below is my javascript code, this you can call from the custom button click on the form using Ribbon workbench. This will call your action which will trigger plugin

    function CallActionFromJavaScript() { 

    var accountId = Xrm.Page.data.entity.getId();
    var entityName = "account";
    var requestName = "new_customaction";
    var appnumber = Xrm.Page.data.entity.attributes.get('new_leapcasenumber').getValue();
    var new_crmcustomerid = Xrm.Page.data.entity.attributes.get('new_crmcustomerid').getValue();
    if(new_crmcustomerid == null){
    alert("Save record before sending to Portal?");
    } else if(appnumber != null){
    if(appnumber.trim().length == 4)
    alert("This account has already been sent to portal.");
    }
    else
    ExecuteAction(accountId, entityName, requestName);
    }
    function ExecuteAction(entityId, entityName, 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 += " </b:value>";
    requestXML += " </a:KeyValuePairOfstringanyType>";
    requestXML += " </a:Parameters>";
    requestXML += " <a:RequestId i:nil=\"true\" />";
    requestXML += " <a:RequestName>" + requestName + "</a:RequestName>";
    requestXML += " </request>";
    requestXML += " </Execute>";
    requestXML += " </s:Body>";
    requestXML += "</s:Envelope>";
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", 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;
    alert("Customer has been sent to your portal. Please login to portal and complete the form.");
    }

    If you find it helpful, Please mark my answer as verified.

    Thanks,

    Shahbaaz

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    You can refer this:

    community.dynamics.com/.../how-to-trigger-plugins-on-custom-messages-using-actions-in-dynamics-365

    Hope this helps

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Amit,

    Here is one example of custom action and calling javascript.

    community.dynamics.com/.../web-api-executing-custom-action-via-javascript

    From plugin you can check below reference

    deepakexploring.wordpress.com/.../actions-in-crm-2013

    Hope this helps.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans