In CRM plugin, “IExecutionContext” contains 2 properties

  • UserId
    • Gets the GUID of the user for whom the plug-in invokes “on behalf of”.
  • InitiatingUserId
    • Gets the GUID of the user under which the current pipeline is executing.

Consider a scenario

  • You have a user “RAJ” with “Sales Person” role with only “User Level” “Read” privilege on ‘Contact’
  • You have a plugin on Post Deletion of ‘Contact’ with name “PostContactDelete”
  • Assume in one particular scenario user “RAJ” should be able to delete a ‘Contact’
  • So you can run the “PostContactDelete” plugin in the user with “SystemAdministrator” role
    • (i.e., Set “Run in User’s Context” to User with admin role; In sample screen shot below I chosen my admin user whose name is  ‘CRM WaSu1)
Run in User Context
Run in User Context
  • When User “RAJ” logs in and try to delete ‘Contact’ the plug-in “PostContactDelete” fires. When you debug
    • IExecutionContext.UserId = GUID of  SystemAdministrator (i.e., OnBehalfOf User ‘RAJ’)
    • IExecutionContext. InitiatingUserId =GUID of  RAJ   (i.e., Actual User)

🙂

Advertisements
Advertisements

3 responses to “UserId & InitiatingUserId properties in Plugin of CRM”

  1. Naresh Veginati Avatar

    I tried impersonation with network credentails but it’s not working. the crm is IFD crm.
    Can you please help me….

  2. Nawaf Avatar
    Nawaf

    Can you please fix the image titled “Plugin Run in User’s Context” it cannot be displayed.

    1. Rajeev Pentyala Avatar

      Its fixed. Thanks for pointing out.

Leave a comment