I am unclear as to how to get output parameters using Web Api for custom actions.
I have created a custom action that creates an email with an attached report, and then returns EmailId as an output parameter.
I assign the returned email ID to the local output parameter.
I call the action using web api.
function CallAction() {
var regNumber = Xrm.Page.getAttribute("xxxxxxxxxxxxxxxxxxxr").getValue();
var Id = Xrm.Page.data.entity.getId().substring(1, 37);
var serverURL = Xrm.Page.context.getClientUrl();
var emailid="";
var parameters = {};
parameters.ReferenceNumber = regNumber;
parameters.ReportName = "Test";
console.log(Id);
var req = new XMLHttpRequest();
req.open("POST", serverURL + "/api/data/v8.2/xxxxxxxxxxxxxxxx(" + Id + ")/Microsoft.Dynamics.CRM.xxxxxxxxxxxxxxxxxxxxx", 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 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 200) {
var results = JSON.parse(this.response);
if(results==null)
console.log("Results null");
else
{
console.log("Results NOT null");
console.log(this.response);
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
};
req.send(JSON.stringify(parameters));
}
I get null for EmailID in the response body.
Is this not the correct approach?
Thanks
ngetz