locked
Adding Notes (Annotation) in CRM 2011 RRS feed

  • Question

  • Hi,

    I am trying to add Notes to the existing records in CRM 2011.

    The records are present in custom entities. I have tried to add notes using create method of Organization Service.

    This inserted an entry to annotation entity(notes) , but the note is not linked to the Custom entity record.

    I have specified the notes fields subject, notetext and object id ( GUID of record in Custom entity) and in related entities specified the CUstom Entity details.

    This did not help.

    I have also tried the update method to update the custom entity and also to insert a note.

    This also didnt work.

    Can anyone suggest how can achieve this.

    Thanks,

    Deepthi

    • Moved by Leonid Ganeline Thursday, December 6, 2012 5:15 PM CRM question (From:BizTalk Server General)
    Thursday, December 6, 2012 4:18 PM

Answers

  • Hi,

    Set the object type code along with guid. You can get the object type code for custom entity using below SQL query.

    select ObjectTypeCode
    from Entity
    where
    logicalname='logical_Name’

    Thanks,

    Pankaj

    • Proposed as answer by Pankaj mohite Wednesday, December 19, 2012 5:39 AM
    • Marked as answer by DeepthiAdith Tuesday, February 19, 2013 4:21 PM
    Wednesday, December 19, 2012 5:39 AM
  • Hi,

    Set the object type code along with guid. You can get the object type code for custom entity using below SQL query.

    select ObjectTypeCode
    from Entity
    where
    logicalname='logical_Name’

    Thanks,

    Pankaj

    My code worked without setting the annotation.ObjectTypeCode property. I also tried setting it too, but then it threw a null object reference error when i tried to save (via IOrganizationService.Create(annotation))

    But for reference this is how I got my ObjectTypeCode

    select ObjectTypeCode
    from EntityLogicalView
    where LogicalName = 'new_expenseform'

    It was located in a view. Also here is a great article on attaching files as notes to custom entities:

    lakshmanindian.wordpress.com/2012/11/01/attachments-in-microsoft-dynamics-crm-2011/

    • Marked as answer by DeepthiAdith Tuesday, February 19, 2013 4:21 PM
    Wednesday, February 13, 2013 12:03 PM

All replies

  • Hi,

    did you also set the "objecttypecode" attribute? Please post your code so that we can identify the issue.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    • Proposed as answer by Daniel Kasi Tuesday, May 19, 2015 11:36 AM
    Friday, December 7, 2012 7:39 AM
  • Hi,

    I agree with Pavlso, when relating an annotation with another entity following attributes are very important. Following is a Silverlight Code 

    Annotation a = new Annotation();
    // Relate this annotation to another entity 
                a.ObjectId = new EntityReference();
    // set Guid of related Object (in this case account)
                a.ObjectId.Id = new Guid("51E590D2-C841-E211-A139-1CC1DE6E6BAE" );
                // Set Logical name of the related entity (in                         my case it is account it can be different for you
                a.ObjectId.LogicalName = "account";
                // Name of the related entity 
                a.ObjectId.Name = "A Store (sample)";
                // File name if required 
                a.FileName = "SamplefileName.doc";
                a.MimeType = "doc";
                a.FileSize = fileContent.Length;
                a.DocumentBody = System.Convert.ToBase64String(fileContent); ;
                //New Annotation to be Created by Silverlight;
                _context.AddToAnnotationSet(a);
                _context.BeginSaveChanges(OnCreateAnnotationComplete, a);

    Hope this helps


    -Devashish
    http://thecrmworld.wordpress.com
    http://ebizartisans.com

    Friday, December 14, 2012 10:24 AM
  • hi,

    Create and attach a file to Notes.

    string strMessage=”this is a demo”;
    byte[] filename = Encoding.ASCII.GetBytes(strMessage);
    string encodedData = System.Convert.ToBase64String(filename);
    Entity Annotation = new Entity(“annotation”);
    Annotation.Attributes["objectid"] = new EntityReference(“EntityName”,GUID);
    Annotation.Attributes["objecttypecode"] = “EntityNAME”;
    Annotation.Attributes["subject"] = “Demo”;
    Annotation.Attributes["documentbody"] = encodedData;
    Annotation.Attributes["mimetype"] = @”text/plain”;
    Annotation.Attributes["notetext"] = “Sample attachment.”;
    Annotation.Attributes["filename"] = “Demo.txt”;
    Service.Create(Annotation);

    original post by Mahender Pal in this blog


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, December 14, 2012 11:58 AM
  • Hi,

    Set the object type code along with guid. You can get the object type code for custom entity using below SQL query.

    select ObjectTypeCode
    from Entity
    where
    logicalname='logical_Name’

    Thanks,

    Pankaj

    • Proposed as answer by Pankaj mohite Wednesday, December 19, 2012 5:39 AM
    • Marked as answer by DeepthiAdith Tuesday, February 19, 2013 4:21 PM
    Wednesday, December 19, 2012 5:39 AM
  • Hi,

    Set the object type code along with guid. You can get the object type code for custom entity using below SQL query.

    select ObjectTypeCode
    from Entity
    where
    logicalname='logical_Name’

    Thanks,

    Pankaj

    My code worked without setting the annotation.ObjectTypeCode property. I also tried setting it too, but then it threw a null object reference error when i tried to save (via IOrganizationService.Create(annotation))

    But for reference this is how I got my ObjectTypeCode

    select ObjectTypeCode
    from EntityLogicalView
    where LogicalName = 'new_expenseform'

    It was located in a view. Also here is a great article on attaching files as notes to custom entities:

    lakshmanindian.wordpress.com/2012/11/01/attachments-in-microsoft-dynamics-crm-2011/

    • Marked as answer by DeepthiAdith Tuesday, February 19, 2013 4:21 PM
    Wednesday, February 13, 2013 12:03 PM