Answered by:
CRM 2011 - Plugin - Associate Entity References

Question
-
I have written a plugin for the Associate message.
I am linking entity 2 to entity 1.
How can I get the GUID for entity 1 within my plugin?
If I look at the InputParameters, the Target object is entity 2:
EntityReference entity = (EntityReference)context.InputParameters["Target"];
ePartners CRMMonday, April 25, 2011 4:00 PM
Answers
-
I found it with:
EntityReferenceCollection relatedentities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"]; if (relatedentities[0].LogicalName != "quote") return; EntityReference quote = new EntityReference("quote", new Guid(relatedentities[0].Id.ToString()));
ePartners CRM- Marked as answer by ePartners UK Monday, April 25, 2011 5:05 PM
Monday, April 25, 2011 5:05 PM
All replies
-
Iterating around the Input Parameters:
Results: "Target", "Relationship", "RelatedEntities"String parameters = ""; foreach (KeyValuePair<string,object> attr in context.InputParameters) { parameters += attr.Key.ToString(); } throw new Exception(parameters);
I am hoping I can find entity 1 in the RelatedEntities object
ePartners CRMMonday, April 25, 2011 4:43 PM -
InputParameters will contain parameters with the same names (for the most part) as the name of the property on the request. For this message, as you can see, there are three parameters:
- Target -- Root Entity
- Relationship -- Relationship between the entities
- RelatedEntities -- List of records that will be related, which is a collection of related entities.
For instance, if the following was executed:
service.Associate("account", accountId, new Relationship("Account_Tasks"), relatedTasks);
The plug-in will see the following parameters:
- Target -- EntityReference ("account", accountId)
- Relationship -- Relationship ("Account_Tasks")
- Related Tasks -- List of tasks that are being associated.
You'll want to add a filter to the Execute method to not do your processing if it is not the relationship that you are looking for.
Michael
- Proposed as answer by Michael B. Scott - MSFTMicrosoft employee Monday, April 25, 2011 4:53 PM
Monday, April 25, 2011 4:53 PM -
I found it with:
EntityReferenceCollection relatedentities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"]; if (relatedentities[0].LogicalName != "quote") return; EntityReference quote = new EntityReference("quote", new Guid(relatedentities[0].Id.ToString()));
ePartners CRM- Marked as answer by ePartners UK Monday, April 25, 2011 5:05 PM
Monday, April 25, 2011 5:05 PM