shytikov
shytikov

Reputation: 9558

Find out to which entity type annotation belongs on pre-operation

I have very special situation with annotation entity in Dynamics CRM.

Since record of this type could belong to almost any entity type in the system, it becomes impossible to find out to which exactly entity type it belongs before retrieving it.

This is what I have discovered so far. I checked every single possibility, but haven't found any information either in the execution context of the plugin, or in any other place.

Based on your experience, may be you can point on some kind indirect indicator that shows on pre-operation stage of the Retrieve / RetrieveMultiplemessage for annotation to which entity this annotation really belongs to.

For example, I have notes on accounts and contacts. I want plugin to fire only when RetrieveMultiple is called for annotations linked to accounts only.

Upvotes: 1

Views: 2388

Answers (1)

Guido Preite
Guido Preite

Reputation: 15138

The attribute binding an annotation to the record is the objectid field.

objectid is an EntityReference so you can know the entity logicalname casting the field:

EntityReference objectRef = (EntityReference)annotation["objectid"];
string entityName = objectRef.LogicalName;

the same information is stored inside the objecttypecode field.

If you need to retrieve all the notes related to accounts, you can use this FetchXml:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="annotation">
    <attribute name="subject" />
    <attribute name="notetext" />
    <attribute name="filename" />
    <attribute name="annotationid" />
    <order attribute="subject" descending="false" />
    <link-entity name="account" from="accountid" to="objectid" alias="ad"></link-entity>
  </entity>
</fetch>

It's the FetchXml generated by this Advanced Find:

enter image description here

Upvotes: 2

Related Questions