email case association? RRS feed

  • Question

  • Hello - I'm creating a new case based on an email that's received in my CRM system. After I create the case, I want to associate the email with it, since that is the email from which the case was initiated. I thought the following code would work but it returns an "unknown error":

    email.RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseId);
    service.Associate(Incident.EntityLogicalName, caseId, new Relationship("Incident_Emails"),
    new EntityReferenceCollection { new EntityReference(Email.EntityLogicalName, email.Id) });

    What's missing here? I looked at the entity relationships in customization and it shows a parental relationship between incident and email on "regarding" so I set the email RegardingObjectId property to the ID of the case that I created earier in the method before calling Associate.

    Any idea what might be causing this error?  Am I not setting something correctly or simply not using the correct approach?

    Friday, July 19, 2013 1:20 AM

All replies

  • If you are just trying to set the Regarding field you can use a normal Update or set it during Create, no need for anything else.

    email.RegardingObjectId = new EntityReference("incident", new Guid("988DB730-0BD9-E211-8F55-B4B52F67E622"));

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, July 19, 2013 2:38 AM
  • When the email plugin gets called post-save, this code: 

    email.RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseId);

    returns the following error:

    "Cannot update subject or description unless email is in draft status"

    I can simply use the following code in pre-save without error:

    email.RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseId);

    However, I would prefer to use post-save/asyncronous for better performance because I think putting the logic in pre-save will make the save operation longer as opposed to letting supporting processes run in the background, right?
    Friday, July 19, 2013 3:54 PM