I am trying to create an email entity in Dynamics 365 using Logic Apps. I am filling in the From and Recipient fields but the when I check the record created in Dynamics, I see that these fields are empty. I know that to and from fields are activity parties in Dynamics 365 email entity. Do we have a sample json which I can use in Logic Apps to create an Email Activity with To and From fields set?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
As per the product group its not available right now to create and set to and from fields of email entity from logic apps
回答2:
Sorry, answering without access to laptop. And this is not straightforward answer for you. But just a start to build your own request Json object.
Replace your record guids in below snippet & execute this in browser console or CRM js web resource. Take the JSON.stringify(email)
at the end & that's what you're looking for.
var serverURL = Xrm.Page.context.getClientUrl();
var email = {};
email["subject"] = "Email Subject";
email["description"] = "email body description";
email["regardingobjectid_contact@odata.bind"] = "/contacts(guid1)";
//activityparty collection
var activityparties = [];
//from party
var from = {};
from["partyid_systemuser@odata.bind"] = "/systemusers(guid2)";
from["participationtypemask"] = 1;
//to party
var to = {};
to["partyid_contact@odata.bind"] = "/contacts(guid3)";
to["participationtypemask"] = 2;
activityparties.push(to);
activityparties.push(from);
//set to and from to email
email["email_activity_parties"] = activityparties;
var req = new XMLHttpRequest();
req.open("POST", serverURL + "/api/data/v8.0/emails", 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.setRequestHeader("Prefer", "return=representation");
req.onreadystatechange = function() {
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 201) {
var emailUri = this.getResponseHeader("OData-EntityId");
}
else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(email));
}
In case if you need it, Code referred from this blog.