Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

Add Note To Existing Case Using .Net in Microsoft Dynamics CRM 2011

Leave a comment

  • Suppose you have customized the “Case” Entity to match the business of a call center in which client reports complaints which are save as cases, and you would like to add a comment to this case.
  • Microsoft Dynamics CRM 2011 is implementing this by default by the “Note” Entity which has a relationship with the “Case” Entity.
  • How to Create a Note and relate it to specific case ?!

Code:

 Using Early Bound

//”Annotation” is the schema name while “Note” is the display name
Annotation NewAnnotation = new Annotation();

//The comment you want to write to this specific case
NewAnnotation.NoteText = “your comment”;

//”incident” is the logical name of the “Case” Entity and IncidentID is the GUID of the record.
NewAnnotation.ObjectId = new Microsoft.Xrm.Client.CrmEntityReference(“incident”, IncidentID);

//Set the title of the “Note”
NewAnnotation.Subject +=”The title of the Note”;

// Add the Note
context.AddObject(NewAnnotation);

// Save the changes
context.SaveChanges();

Using Late Bound

Entity Note= new Entity(“Annotation”);

//The comment you want to write to this specific case
Note[“notetext] = “your comment”;

//The “ObjetID” is the ID if the record you want to assign the note to it (Note can be assigned to many type of entities not just case)

//”incident” is the logical name of the “Case” Entity and IncidentID is the GUID of the record.
Note[“ObjectId”] = new Microsoft.Xrm.Client.CrmEntityReference(“incident”, IncidentID);

//Set the title of the “Note”
Note[“Subject”] = “Your Title”;

//Create the record
OrganizatoinService.Create(Note);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s