web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Reassigning Annotation entity to new custom entity

(0) ShareShare
ReportReport
Posted on by 306

Hi,

I am trying to switch a note record (Annotation entity) from one custom entity to another by changing the ObjectId and ObjectTypeCode. When I try and save the changes I get the following error;

"Invalid type for entity id value"

I have made sure the id and type code are correct for the new entity. is there anything wrong with this code?


     foreach (var entity in returnValues.EntityCollection.Entities)
            {
                var note = (Annotation) entity;

                //Just remove Key field of annotation
                note.AnnotationId = null;

                //Replace referencing object with destination object
                note.ObjectId = new EntityReference(destEntity.LogicalName, destEntity.Id);
                note.ObjectTypeCode = destObjectTypeCode.ToString();
                //And Create the annotation record
                service.Create(note);
            }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Deepesh161 Profile Picture
    6,317 on at

    You are trying to use service.create. Rather it should be update?

  • mluce Profile Picture
    306 on at

    I set the Id to null so it should Create.  If i comment that out and change it to Update, it throws an exception again with just the object type code as the Message. ("10010") which is the code for the destination entity.

  • Verified answer
    mluce Profile Picture
    306 on at

    It appears my proxy class was wrong.  I have done this which works;

                   entity.Attributes["objectid"] = new EntityReference(destEntity.LogicalName, destEntity.Id);

                   entity.Attributes["objecttypecode"] = destEntity.LogicalName;

                   service.Update(entity);

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at

    Mluce,

    You use Create, it does mean you want to duplicate the existing note? Create a new more note, isn't it?

    Why you don't just use:

    Annotation note= new Annotation()

                       {

                           Subject = "Example Annotation",

                           FileName = "ExampleAnnotationAttachment.txt",

                           DocumentBody = Convert.ToBase64String(

                               new UnicodeEncoding().GetBytes("Sample Annotation Text")),

                           MimeType = "text/plain",

                       };

    Or you can just like this:

    Entity note= new Entity(“annotation”);

    note["objectid"] = new EntityReference(destEntity.LogicalName, destEntity.Id);

    note["objecttypecode"] = destEntity.LogicalName;

    note["subject"] = entity["subject"];

    note.["documentbody"] = entity["documentbody"];

    note.["mimetype"] = entity["mimetype"];

    note.["notetext"] = entity["notetext"];

    note.["filename"] = entity["filename"];

    Service.Create(note);

    And make sure that the guid of your dest entity is correct.

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans