Impersonation available using WEB API in Dynamics CRM 2016

By | February 26, 2016

Introduction:

Microsoft Dynamics CRM online 2016 update and Dynamics CRM 2016 (on-premises) has introduced a new concept called the Web API. This can be used across a wide variety of programming languages, platforms, and devices. One of the features of Web API is Impersonation.

Back in the days of CRM 4, Impersonation through scripting was supported by including the impersonation details in the header of the SOAP request.

Later this feature was removed and there was no way to impersonate a user through Scripting.

Impersonation is used when you want to execute business logic (code) on behalf of another CRM user. This is necessary because the CRM Web services can be called by various clients and services on behalf of a CRM user. Impersonation involves two different users where User (X) is used for executing the code to perform some tasks on behalf of another user (Y).

Walkthrough of Impersonation through Script

The User account (X) has to be given the prvActOnBehalfOfAnotherUser privilege to perform the task.

In order to impersonate a user through the Web API, you need to add ‘MSCRMCallerID’ key with GUID of the impersonated user. In the below example, a new contact entity is created on behalf of the user with systemuserid B65AB846-7EBE-E511-80DF-00155D06F307.

Here’s the code which helps you to impersonate a user through the Web API.

In the above code, the only addition is the following line of code

Once the callerid is set, the record is created using the privileges that is assigned to the user specified in the callerid rather than the logged in user.

Conclusion:

On a concluding note, impersonation helps to perform operations on behalf of other users if the system account running the code has the necessary privileges.

You may also like to read : Make your Dynamics CRM life easy with Inogic Dynamics CRM Solutions.

Leave a Reply