Hi Guys,
I'm trying to create an Email Activity from the Incident page of our CRM (CRM2015)
it works, but i cant figure out how to populate the "to" and "from"
I'm sure I'm missing a small detail, just not sure what it is :(
var emailSubject=parent.Xrm.Page.getAttribute('title').getValue();
var CaseOwner=parent.Xrm.Page.getAttribute('ownerid').getValue()[0]
var FromParty = new Array()
FromParty[0] = new Object();
FromParty[0].id =id= CaseOwner.id;
FromParty[0].entityType = "systemuser";
FromParty[0].type = "8";
FromParty[0].name = CaseOwner.name;
var entity = {};
entity.RegardingObjectId = {
Id: parent.Xrm.Page.data.entity.getId(),
LogicalName: "incident"
};
entity.Subject = "re:" + emailSubject
entity.From = FromParty
var req = new XMLHttpRequest();
req.open("POST", encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/EmailSet"), false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 201) {
var result = JSON.parse(this.responseText).d;
} else {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
result=JSON.parse(req.responseText).d;
var EmailId=result.ActivityId;
var options = {openInNewWindow : true};
parent.Xrm.Utility.openEntityForm("email",EmailId,null,options) // for now, cant figure out how to use windows.open for a email form.