Through JS calling the Action and Plugin register on Action
///
First I have created a bound Action for Opportunity Entity with Input Parameter of String Type
Parameter Name = InputParameter
Then this Js code
function callActionToplugin(primaryControl){
var formContext = primaryControl
var actionName = "abc_ActionName";
var Id = formContext.data.entity.getId().replace('{', '').replace('}', '');
//Pass the input parameters to action
var data = {
"InputParameter": Id
};
//Create the HttpRequestObject to send WEB API Request
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/opportunities("+Id+")/Microsoft.Dynamics.CRM.abc_ActionName", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */)
{
req.onreadystatechange = null;
if (this.status == 200 || this.status == 204)
{
setTimeout(() => {
//formContext.ui.refreshRibbon(true);
window.top.location.reload();
}, 100);
}
else
{
var error = JSON.parse(this.response).error;
alert("Error in Action: "+error.message);
}
}
};
//Execute request passing the input parameter of the action
req.send(JSON.stringify(data));
}
///////////Then Read the Input Inside the plugin:
if (context.PrimaryEntityName.ToLower().Equals("opportunity"))
{
trace.Trace("Update of Opportunity");
if (context.InputParameters.Contains("InputParameterName"))
{
var MyInputParam = (string)context.InputParameters["InputParameterName"];
trace.Trace("InputParameter Entity Present: "+ MyInputParam);
Guid oppid = new Guid(MyInputParam);
trace.Trace("oppidt: " + oppid);
Entity entityData = crmService.Retrieve("opportunity", oppid, new ColumnSet(true));
}
}