Reputation: 174
I'm writing a plug in for CRM 2011 using the SDK. The plugin is meant to execute synchronously as a post-operation plugin. The plugin will trigger a step that should retrieve two attributes and perform some logic based on what it finds. Unfortunately, however, the attributes in question aren't in the Attributes collection of the target. (they aren't the fields being updated by the user). I need to be able to read those attributes even if they aren't actively being updated. Here's my code:
Dim context As IPluginExecutionContext = CType(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
If context.InputParameters.Contains("Target") AndAlso TypeOf context.InputParameters("Target") Is Entity Then
Dim entity As Entity = CType(context.InputParameters("Target"), Entity)
If entity.LogicalName.Equals("contact") Then
Try
Dim attribute1 As Object = entity.Attributes("abc") ' not in Attributes collection
Dim attribute2 As Object = entity.Attributes("def") ' not in Attributes collection
Catch ex as Exception
...
So my question is, what's the best way to retrieve attributes of an entity from within a plugin? Do I need to issue a separate query to CRM using the OrginizationService, or is there a way to grab it from the context?
Thanks!
Upvotes: 2
Views: 3950
Reputation: 17562
Two ways.
Upvotes: 2