locked
REST & ActivityParty: Populating two values into the "To" field on an Email activity RRS feed

  • Question

  • Using REST and JavScript, I am trying to populate the "To" field in the Email activity with values from my fields "Contact 1" and "Contact 2"  The code below works, but it overwrites the Contact 1 value and in the "To" field there is only 1 value.

    Does anyone know how to populate two values into the "To" field or any lookup field using REST?

    function EmailCallBack(result) {
        email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
        var Contact1 = Xrm.Page.data.entity.attributes.get("apd_contact1").getValue()[0].id;
     
        var activityPartyFrom = new Object();
        activityPartyFrom.PartyId = {
            Id: Contact1,
            LogicalName: "contact"
        };
        // Set the "activity" of the ActivityParty
        activityPartyFrom.ActivityId = {
            Id: result.ActivityId,
            LogicalName: "email"
        };
        activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
        SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
             
        var Contact2 = Xrm.Page.data.entity.attributes.get("apd_contact2").getValue()[0].id;
         
        var activityPartyFrom = new Object();
        activityPartyFrom.PartyId = {
                Id: Contact2,
                LogicalName: "contact"
         };
        
         // Set the "activity" of the ActivityParty
         activityPartyFrom.ActivityId = {
             Id: result.ActivityId,
             LogicalName: "email"
         };
         activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients      
         SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
    }
    //ActivityParty From Callback
    function ActivityPartyFromCallBack(result) {
    }


    Mike Karls

    Tuesday, October 29, 2013 6:37 PM

All replies

  • Any one out there who can help?

    Mike Karls

    Wednesday, October 30, 2013 1:14 PM
  • To create multiple recipients you will need an Update of the email entity, setting the 'to' attribute to an array containing the 2 activityparty instances, instead of using a Create of the activityparty


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Wednesday, October 30, 2013 9:20 PM
    Moderator