0
votes

I have a custom entity A, which contains an annotation column (a built in entity that support upload files). I want to be able to read the annotation id for the entity record i get when a plugin is triggered.

The entity has all attributes i am except the annotation in any form, no referenced entity. It is worth to note that annotation entity is listed in the relationship tab but there is no reference to annotation field in the fields view in Dynamics online.

How can i lookup or get the annotation id in the entity A in a custom plugin.

The plugin triggers on the create message from custom entity A, since it has all the columns i want to process in addition the file uploaded in the annotation entity.

I looked at the sample sdk sample, but it is not useful since i want to get the annotation id first before retrieving it.

https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg328429(v=crm.8)

Any pointers or sample are appreciated it.

1
Annotation (Notes) is like subgrid to capture 1:N records but different UI. For sure - You cannot see a lookup column in entity A (may be custom relationship ??) When is record getting created & when’s attachment uploaded? - Arun Vinoth - MVP

1 Answers

-1
votes

There is a one-to-many relationship from your custom entity to the annotation entity, because there can be many notes (and attachments) for each custom entity record.

Your plugin should create a new annotation record and set the objectid and objecttypecode fields on that annotation record to the current custom record that was just created.

Here's an example that uploads a simple text file and relates it to a custom entity record that was just created:

var newId = <new just-created custom entity record id goes here>;

var sampleFileText = "Hello World";
var sampleFileBytes = Encoding.ASCII.GetBytes(sampleText);
var sampleFileBase64 = System.Convert.ToBase64String(fileBytes);

var annotation = new Entity("annotation");
annotation.Attributes["objectid"] = new EntityReference("new_entity", newId); // <- Your custom entity name and new id here
annotation.Attributes["objecttypecode"] = "new_entity"; // <- Your custom entity name here
annotation.Attributes["subject"] = "Uploaded File";
annotation.Attributes["documentbody"] = sampleFileBase64 ;
annotation.Attributes["mimetype"] = @"text/plain";
annotation.Attributes["notetext"] = "Uploaded File";
annotation.Attributes["filename"] = "UploadedFile.txt";

Service.Create(annotation);