Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Call action that trigger a plugin from js

Posted on by 75

 have a scenario where I need to trigger a plugin on a ribbon button click (SYNCH), I have setup the commands and buttons, I have created a custom action,that will be registered in the plugin reg tool to wire up the event. I have tested the ribbon button that just does a simple hello world, so I am sure that the basics are dine and set. My issue lies when I try to call the function that does a SOAP invocation. Here is my code below. 

function CallAction() {
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/products/Microsoft.Dynamics.CRM.new_ProductPr", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

}

2318.s.PNG
}

*This post is locked for comments

  • Suggested answer
    Justinjose Profile Picture
    Justinjose 2,707 on at
    RE: Call action that trigger a plugin from js

    Hi Jf Marwen,

    Can you disable the plugin and create a step in action, some thing like create account or contact to make sure "Action" works with out any error.

    Thanks

    Justin Jose

  • Jf Marwen Profile Picture
    Jf Marwen 75 on at
    RE: Call action that trigger a plugin from js

    my action is without input , it call to a plugin

  • CRASH Profile Picture
    CRASH on at
    RE: Call action that trigger a plugin from js

    What input/output are you using with action, if any of them is required and is of type GUID, you need to provide GUID in code.

  • Jf Marwen Profile Picture
    Jf Marwen 75 on at
    RE: Call action that trigger a plugin from js

    Vaibhaw Wadhwa , yes "new_ProductPr" is this name of your action  and it is active

    the error "Sys.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: '' is not a valid Guid value."

  • CRASH Profile Picture
    CRASH on at
    RE: Call action that trigger a plugin from js

    community.dynamics.com/.../why-my-action-is-not-available-through-webapi

    Have a look at this as well

  • CRASH Profile Picture
    CRASH on at
    RE: Call action that trigger a plugin from js

    "new_ProductPr" Is this name of your Action?

    If yes, is it in active state?

  • Jf Marwen Profile Picture
    Jf Marwen 75 on at
    RE: Call action that trigger a plugin from js

    This is the code from CRMRESTBUILDER 

    var parameters = {};
    var entity = {};
    entity.id = "";
    entity.entityType = "product";
    parameters.entity = entity;

    var new_ProductPrRequest = {
    entity: parameters.entity,

    getMetadata: function() {
    return {
    boundParameter: "entity",
    parameterTypes: {
    "entity": {
    "typeName": "mscrm.product",
    "structuralProperty": 5
    }
    },
    operationType: 0,
    operationName: "new_ProductPr"
    };
    }
    };

    Xrm.WebApi.online.execute(new_ProductPrRequest).then(
    function success(result) {
    if (result.ok) {
    //Success - No Return Data - Do Something
    }
    },
    function(error) {
    Xrm.Utility.alertDialog(error.message);
    }
    );

    not working

  • CRASH Profile Picture
    CRASH on at
    RE: Call action that trigger a plugin from js

    Have you copy pasted exact same code?

    If not please share the code you have pasted, i have shared a link with my reply as well, you can find a managed solution on that link CRMRESTBUILDER.zip(something along that line), import it on your CRM instance, go to settings-->customization, you will see a button for CRM rest builder near ribbon, click on that to open solution, and create a code to run your action from there, most of the time, code created from that tool will just run fine, without editing.

  • Jf Marwen Profile Picture
    Jf Marwen 75 on at
    RE: Call action that trigger a plugin from js

    Vaibhaw Wadhwa , when i used your code i got this error www.PNG

  • Suggested answer
    chauhanhardik Profile Picture
    chauhanhardik 685 on at
    RE: Call action that trigger a plugin from js

    Hi Jf Marwen,

    The code given by Pravin Pawar will trigger the action to be called on click of ribbon button, then register the plugin in Plugin registration tool and call it using the action name. This will fire plugin on click of ribbon button.

    Regards,

    Hardik Chauhan

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

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