以下代码将在CRM中创建电子邮件活动,但我无法弄清楚如何添加多个收件人。如果我尝试添加第二个收件人,它只会替换第一个收件人。
function CreateEmail() {
alert("CreateEmail Begin");
var email = new Object();
email.Subject = "Sample Email Using REST";
SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
}
// Email Call Back function
function EmailCallBack(result)
{
var activityParty=new Object();
// Set the "party" of the ActivityParty // EntityReference of an entity this activityparty relatated to.
activityParty.PartyId = {
Id: "8384E684-7686-E011-8AF0-00155D32042E",//replace this with the contactid from your system.
LogicalName: "contact"
};
// Set the "activity" of the ActivityParty
// EntityReference.
activityParty.ActivityId = {
Id: result.ActivityId,
LogicalName: "email"
};
// Set the participation type (what role the party has on the activity).
activityParty.ParticipationTypeMask = { Value: 2 }; // 2 mean ToRecipients
SDK.JScriptRESTDataOperations.Create(activityParty, "ActivityParty",ActivityPartyCallBack , function (error) { alert(error.message); });
}
function ActivityPartyCallBack(reuslt)
{
alert("Process Completed");
}
答案 0 :(得分:2)
这是一个创建包含多个收件人的电子邮件的代码段。关键是设置email_activity_parties属性,以便我们可以传递一个对象。
基本上,email_activity_parties允许我们提交一个Object数组而不是顶级Object。
function CreateEmail() {
debugger;
var email = new Object();
email.Subject = "my email";
email.Description = "my email description";
var activityParties = new Array();
var partyObj0 = new Object();
partyObj0.PartyId = { Id: "a9568879-e61c-e411-80bb-000c29c1100f", LogicalName: "systemuser" };
partyObj0.ParticipationTypeMask = { Value: 1 };
activityParties[0] = partyObj0;
var partyObj1 = new Object();
partyObj1.PartyId = { Id: "b23f7a24-2223-e411-80c8-000c29c1100f", LogicalName: "contact" };
partyObj1.ParticipationTypeMask = { Value: 2 };
activityParties[1] = partyObj1;
var partyObj2 = new Object();
partyObj2.PartyId = { Id: "ffd09f25-1748-e411-80cb-000c29c1100f", LogicalName: "contact" };
partyObj2.ParticipationTypeMask = { Value: 2 };
activityParties[2] = partyObj2;
//set email.email_activity_parties to activityParties
email.email_activity_parties = activityParties;
SDK.REST.createRecord(email, "Email", EmailCallBack, function (error) { alert(error.message); });
}
// Email Call Back function
function EmailCallBack(result) {
debugger;
}
答案 1 :(得分:0)
我不担心会有一个REST示例,但是在C#SOAP中你必须传递一组实体,或许它们在REST中是一样的吗?
Entity e = new Entity("phonecall");
e["to"] = new Entity[]
{
ToActivityParty(new EntityReference("contact", contact1)),
ToActivityParty(new EntityReference("contact", contact2)),
};
static Entity ToActivityParty(EntityReference entityReference)
{
Entity party = new Entity("activityparty");
party["partyid"] = entityReference;
return party;
}