locked
target is activityparty in email postsave plugin? RRS feed

  • Question

  • Hello - I selected File > New Activity > Email from the ribbon which opened a new email form.  I entered some info and clicked the Save button.  This went into my post-save Email plugin which was expecting an Email entity but the Target seemed to resolve to an ActivityParty entity.  Can you explain why or under what scenarios an Email plugin would receive an ActivityParty entity and if this is valid then how can I get the Email To, From, Subject and Body values from the ActivityParty entity in this scenario?

    Sunday, July 14, 2013 7:13 AM

Answers

  • if you invoke though the Activity, you will get the activity entity.  it will have that activid ID on the target, with that you can than retrieve the email though EntityReference

    here is a sample on how to send email using activity party info

    // build the 'from' list
    
    EntityReference from = new EntityReference("systemuser", sender);
    
    Entity e_from = new Entity("activityparty");
    
    e_from.Attributes.Add("partyid", from);
    
    EntityCollection ec_FromParty = new EntityCollection();
    
    ec_FromParty.EntityName = "systemuser";
    
    ec_FromParty.Entities.Add(e_from); 
    
    
    
    
    // build the 'to' list.
    
    EntityReference to = new EntityReference("systemuser", mailrecipient);
    
    Entity e_to = new Entity("activityparty");
    
    e_to.Attributes.Add("partyid", to); 
    
    EntityCollection ec_ToParty = new EntityCollection();
    
    ec_ToParty.EntityName = "systemuser";
    
    ec_ToParty.Entities.Add(e_to);
    
    
    
    
    // set the lookup property of the email to the record to which it is related. The
    
    //entity name and the guid of the record needs to be passed.
    
    EntityReference regardingRecord = new EntityReference("<entityName>", regarding);
    
    
    
    
    // set the attributes of the Email object
    
    Entity email = new Entity();
    
    email.LogicalName = "email"; 
    
    email.Attributes.Add("from", ec_FromParty);
    
    email.Attributes.Add("to", ec_ToParty); 
    
    email.Attributes.Add("subject", subject);
    
    email.Attributes.Add("description", body);
    
    email.Attributes.Add("regardingobjectid", regardingRecord);
    
    
    
    
    Guid email_Id = service.Create(email); 
    
    SendEmailRequest sendEmail = new SendEmailRequest();
    
    sendEmail.EmailId = email_Id;
    
    sendEmail.IssueSend = true;
    
    sendEmail.TrackingToken = ""; 
    
    SendEmailResponse response = (SendEmailResponse)service.Execute(sendEmail);

    Sunday, July 14, 2013 9:57 PM
  • What message is the pluginregistrationstep registered on ?

    For a Create or Update message, the Target should always be of the same entity type as the entity the step is registered on. Are you sure you've not registered the step on the activityparty entity instead of (or as well as) the email entity ?


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

    Monday, July 15, 2013 6:10 AM
    Moderator

All replies

  • if you invoke though the Activity, you will get the activity entity.  it will have that activid ID on the target, with that you can than retrieve the email though EntityReference

    here is a sample on how to send email using activity party info

    // build the 'from' list
    
    EntityReference from = new EntityReference("systemuser", sender);
    
    Entity e_from = new Entity("activityparty");
    
    e_from.Attributes.Add("partyid", from);
    
    EntityCollection ec_FromParty = new EntityCollection();
    
    ec_FromParty.EntityName = "systemuser";
    
    ec_FromParty.Entities.Add(e_from); 
    
    
    
    
    // build the 'to' list.
    
    EntityReference to = new EntityReference("systemuser", mailrecipient);
    
    Entity e_to = new Entity("activityparty");
    
    e_to.Attributes.Add("partyid", to); 
    
    EntityCollection ec_ToParty = new EntityCollection();
    
    ec_ToParty.EntityName = "systemuser";
    
    ec_ToParty.Entities.Add(e_to);
    
    
    
    
    // set the lookup property of the email to the record to which it is related. The
    
    //entity name and the guid of the record needs to be passed.
    
    EntityReference regardingRecord = new EntityReference("<entityName>", regarding);
    
    
    
    
    // set the attributes of the Email object
    
    Entity email = new Entity();
    
    email.LogicalName = "email"; 
    
    email.Attributes.Add("from", ec_FromParty);
    
    email.Attributes.Add("to", ec_ToParty); 
    
    email.Attributes.Add("subject", subject);
    
    email.Attributes.Add("description", body);
    
    email.Attributes.Add("regardingobjectid", regardingRecord);
    
    
    
    
    Guid email_Id = service.Create(email); 
    
    SendEmailRequest sendEmail = new SendEmailRequest();
    
    sendEmail.EmailId = email_Id;
    
    sendEmail.IssueSend = true;
    
    sendEmail.TrackingToken = ""; 
    
    SendEmailResponse response = (SendEmailResponse)service.Execute(sendEmail);

    Sunday, July 14, 2013 9:57 PM
  • What message is the pluginregistrationstep registered on ?

    For a Create or Update message, the Target should always be of the same entity type as the entity the step is registered on. Are you sure you've not registered the step on the activityparty entity instead of (or as well as) the email entity ?


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

    Monday, July 15, 2013 6:10 AM
    Moderator