CRM 2011 Plugins – Obtaining User Information

Roshan Mehta, 14 April 2013

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.

 CRM 2011 Plugins Obtaining User Information

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 where a plugin was executed.