Create an email activity using REST Endpoints in CRM2011-2013

此生再无相见时 提交于 2019-12-13 14:09:05

问题


The code below will create a Email Activity in CRM but I can't figure out how to add multiple recipients. If I try to add a second recipient it just replaces the first recipient.

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");
    }

回答1:


Here’s a snippet that creates a email with multiple Recipients. The key was to set the email_activity_parties attribute so that we can pass an object.

Essentially email_activity_parties lets us submit a Array of Object instead a top level 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;

}



回答2:


Dont have a REST sample I'm afraid, but in C# SOAP you have to pass a collection of entities, perhaps its the same in 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;
}


来源:https://stackoverflow.com/questions/26105626/create-an-email-activity-using-rest-endpoints-in-crm2011-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!