Hi All,
My requirement is:
1. Contact Entity we have a button, on click of button action is being called.
2. On click of button i am getting the list of closed cases associated with that contact via web api.
3. Now i need to pass this result (from step 2) to action input parameter.
Action Input parameter created is of type "Entity Collection"
Below is my javascript code on click of button:
function actionFunction()
{
debugger;
var contactId = Xrm.Page.data.entity.getId().slice(1, -1);
var caseResults = getClosedCases(contactId);
if(caseResults != null)
{
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(" +contactId+ ")/Microsoft.Dynamics.CRM.new_Action", 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;
debugger;
if (this.status === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(caseResults)); error is present here
}
}
function getClosedCases(contactId)
{
var results = null;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents?$select=statecode,statuscode&$filter=_contactid_value eq "+contactId+" and statecode eq 1", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var statecode = results.value[i]["statecode"];
var statecode_formatted = results.value[i]["statecode@OData.Community.Display.V1.FormattedValue"];
var statuscode = results.value[i]["statuscode"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
return results; // how will i pass this in action paramater
}
Query: How will i pass "results" (closed cases list) to action parameter.
Any help would be appreciated.
Regards,
Rahul