CRM 2011 Plugins – Obtaining User Information

Developers can use the IPluginExecutionContext service object to obtain contextual information from the CRM platform which is passed to the plugin at run-time. It includes details about the user who triggered the plugin event as well as transactional information handled at the platform layer. In this post, we will see which properties are available to obtain information about a user.

The IPluginExecutionContext object includes the following GUID properties:

  • BusinessUnitId
  • InitiatingUserId
  • UserId

The BusinessUnitId property allows developers to obtain the GUID of the Business Unit the calling user belongs to. For example, user Frosty Stevens belongs to the “Sales” Business Unit. When he performs an action that triggers a plugin, the ID of the “Sales” Business Unit will be returned my invoking this property.

The InitiatingUserId is the GUID of the user who triggered the execution of the plugin. For example, user Frosty Stevens updates an Account record. When the plugin code is executed, the InitiatingUserId property will return the GUID of Frosty Stevens’ user record.

The UserId property is not to be mistaken with the InitiatingUserId property. This property returns the GUID of the user of which custom plugin code is invoked on behalf on. This user is set when defining plugin steps via the Plugin Registration Tool.

capture

There are many more useful properties available via the IPluginExecutionContext. In my next post, we will take a look at how we can obtain information about the organization from which a plugin was executed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s