Skip to content Skip to sidebar Skip to footer

Create An Email Activity Using Rest Endpoints In Crm2011-2013

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.

Solution 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.

functionCreateEmail() {
    debugger;

    var email = newObject();

    email.Subject = "my email";
    email.Description = "my email description";

    var activityParties = newArray();

    var partyObj0 = newObject();
    partyObj0.PartyId = { Id: "a9568879-e61c-e411-80bb-000c29c1100f", LogicalName: "systemuser" };
    partyObj0.ParticipationTypeMask = { Value: 1 };
    activityParties[0] = partyObj0;

    var partyObj1 = newObject();
    partyObj1.PartyId = { Id: "b23f7a24-2223-e411-80c8-000c29c1100f", LogicalName: "contact" };
    partyObj1.ParticipationTypeMask = { Value: 2 };
    activityParties[1] = partyObj1;

    var partyObj2 = newObject();
    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 functionfunctionEmailCallBack(result) {
    debugger;

}

Solution 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?

Entitye=newEntity("phonecall");
e["to"] = newEntity[] 
{ 
    ToActivityParty(newEntityReference("contact", contact1)),
    ToActivityParty(newEntityReference("contact", contact2)),
};

static Entity ToActivityParty(EntityReference entityReference)
{
    Entityparty=newEntity("activityparty");
    party["partyid"] = entityReference;
    return party;
}

Post a Comment for "Create An Email Activity Using Rest Endpoints In Crm2011-2013"