locked
C# Creating Incidents(Cases) RRS feed

  • Question

  • Hi all,

    I've successfully created a Case from an incoming Email using C#, but I have a few fields/entities I'm unable to add to this newly created case.  So far here is what I have:

                Entity returnCase = new Entity("incident");
                returnCase.Attributes.Add("title", emailMessage["subject"]);
                returnCase.Attributes.Add("customerid", emailMessage["regardingobjectid"]);
                returnCase.Attributes.Add("caseorigincode", new OptionSetValue(2));
                returnCase.Attributes.Add("casetypecode", new OptionSetValue(3));

    Which works fine; but my requirements are that I also attach the original email to this new Case.  

    My other requirement is that I set the subject to a default.  (I've used the same code as "customerid", but it will not set the lookup to what I specify)

    Does anyone know how to do these things for a case?

    Thanks,

    Bmckie

    EDIT: HALF-SOLVED, HALF!

    The solution to attaching the email to the Case was to add the following: 

    Relationship relationship = new Relationship("Incident_Emails");
                EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
                relatedEntities.Add(new EntityReference("email", emailRef.Id));
                service.Associate("incident", caseId, relationship, relatedEntities);

    • Edited by Bmckie Thursday, December 12, 2013 8:27 PM half solved
    Thursday, December 12, 2013 6:28 PM

All replies

  • you can to create an incident in Email Create plugin, in this context only after creating an incident, get incident id and attach email to case using following code.

    Entity target = (Entity)this.Context.InputParameters["Target"];
    string emailSubject = target.GetAttributeValue<string>("subject");
    Guid incidentId= CreateIncidentFromEmail(target);
     //Attach email to case
    var caseReference = new EntityReference("incident", incidentid) { Name = emailSubject };
    target.Attributes["regardingobjectid"] = caseReference;

    Thursday, December 12, 2013 7:55 PM
  • The Case Subject is an entity reference to Subject.   You can define a "default" subject (or use  Default).  Pull the guid and add it.  You can use advanced find using a filter (download xml), odata query designer to create query to pull data, or insert a retrievemultiple to grab the default record.  

       var caseSubject = new EntityReference("subject",<default subject guid>);
       returnCase.Attributes.Add("subject",caseSubject);

    Hope this helps. 

    Friday, December 13, 2013 3:36 AM
  • Add case in regarding filed of email and update/save email. Now you able to attach email to that case .

    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Friday, December 13, 2013 4:11 AM