2
votes

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!

1

1 Answers

2
votes

Two ways.

  1. An image in the plugin registration tool, that is like a snapshot of the entity, you can then retrieve the image out of the context - very similar to using the target. This is probably the best way to do it in this case.
  2. Use a retrieve web service call, this is useful if you need to get something from a related entity but is rarely the best option when getting the values from the target entity.

Pre and Post Entity Images