Introduction:
While working on Dynamics 365, we get a chance to work on lot many things.
At times you work on C# or JavaScript or SSRS or SSIS. Having knowledge of so many languages, frameworks, or technologies could be taxing.
Sometimes we face errors while developing something and don’t have control over how it could be fixed.
One such thing was executing Action using Web API.
Prior to v9.0 update, if we tried executing Actions, having a combination of complex and simple output parameters would result in errors like, Resource not found for the segment ‘ActionName’ or Request message has unresolved parameters.
In order to understand what complex and simple parameters are, please check a very well explained blog written by Andrew Butenko.
Now, in v9.0 we don’t have to worry about the combinations of the output parameters.
Irrespective of the combination of the output parameters, we are able to execute the Action.
Code Snippet:
function executeAction(accountId, actionName, clientUrl) { var functionName = "executeAction >>"; var query = ""; try { //Define the query to execute the action query = "accounts(" + accountId + ")/Microsoft.Dynamics.CRM."+actionName; var req = new XMLHttpRequest(); req.open("POST", clientUrl + "/api/data/v9.0/" + query, 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) { //success callback var result = JSON.parse(this.response); } else { //error callback var error = JSON.parse(this.response).error; } } }; req.send(JSON.stringify(data)); } catch (e) { throwError(functionName, e); } }
Conclusion:
We can combine simple and complex output parameters and still execute the Action through Web API in Dynamics 365 v9.0