Sometimes there are scenarios you need to create Global Actions where you don't specify an entity in particularly. When you create such global action and if you need to call that action from your JavaScript code or on Button Click. Here is the way to do that.
Example of calling Global Action Without Parameters:
Create a Global Action
Add Steps and Copy Action Unique Name (My Custom Action)
JavaScript to call Action
//Execute the created global action using Web API.
function CallGlobalCustomAction() { //get the current organization name var serverURL = Xrm.Page.context.getClientUrl(); //query to send the request to the global Action var actionName = "new_MyCustomAction"; // Global Action Unique Name //Pass the input parameters of action var data = {}; //Create the HttpRequestObject to send WEB API Request var req = new XMLHttpRequest(); //Post the WEB API Request req.open("POST", serverURL + "/api/data/v8.0/" + 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) { alert("Action Executed Successfully..."); } 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(window.JSON.stringify(data)); }
Example of calling Global Action with Parameters:
JavaScript to call Action
//Execute the created global action using Web API.
function CallGlobalCustomAction() { //get the current organization name var serverURL = Xrm.Page.context.getClientUrl(); //query to send the request to the global Action var actionName = "new_MyCustomAction"; // Global Action Unique Name//set the current loggedin userid in to _inputParameter of the var InputParameterValue = Xrm.Page.context.getUserId(); //Pass the input parameters of action var data = { "MyInputParameter": InputParameterValue };//Create the HttpRequestObject to send WEB API Request var req = new XMLHttpRequest(); //Post the WEB API Request req.open("POST", serverURL + "/api/data/v8.0/" + 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) { alert("Action Executed Successfully...");//You can get the output parameter of the action with name as given belowresult = JSON.parse(this.response);
alert(result.MyOutputParameter);} 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(window.JSON.stringify(data)); }
It’s interesting to read content. nice post.
ReplyDeleteMicrosoft Dynamics AX Online Training
ReplyDeleteI like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting
angular training
ruby on rails online course
ai online training
Qlikview Training
Spark Training
Your information was very clear. Thank you for sharing.
ReplyDeleteD365 Finance and Operations Online Training
It was really a nice post and I was really impressed by reading this keep updating
ReplyDeleteReact js Online Training
Angularjs Training
NodeJS Online Training Hyderabad
Microstrategy Online Training
Power BI Online Training Hyderabad
AngularJS Online Training
Excellent information with unique content and it is very useful to know about the information based on blogs . Website Development Company in Bangalore | Web Designing Companies in Bangalore | Web Development Company in Bangalore
ReplyDeleteZinavo Technologies Blog : Website Designing Company in Bangalore | Web Designing Company in Bangalore
Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing.
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training
Informative Article...
ReplyDeleteSometime few educational blogs become very helpful while getting relevant and new information related to your targeted area. As I found this blog and appreciate the information delivered to my database.How to get rid of Discord Javascript Error | newscutzy.com
ReplyDeleteNothing remain forever. Then why to keep same patter of work again and again. Why to repeat same strategy for very essay. Use differ strategy for different subjects because every subject has its own meaning. Keep such posts on.Discord Javascript Error
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSpecial thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to
ReplyDelete(hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time.
Contact him now and thank me later.