Recreate Personal Views as System Views with Impersonation in Dynamics 365

Jordan Hohepa, 21 March 2018

Views can be created as both system and personal views. The former will be available to all Users who have permission to view the entities and the latter will be available to the owner and anyone who it is has been shared to. This blog will focus on a simple way using a console application to convert all personal views to system views, as there is currently no way to achieve this using out of the box features. This method will make use of impersonation to retrieve the personal views of all Users and will then loop through them to create system view copies. The example used in this blog is one of many ways you could use impersonation in a console application.

image

The method above is what I used in a console application to complete the task outlined. It starts off by retrieving the Ids of all Users in the system, which can be seen in the code below. It then loops through the list of Ids and sets these to the CallerId of the sdk one at a time. In this case I used OrganizationServiceProxy as my sdk variable to connect to CRM, which I did before calling this method.

image

Once the personal views (which have the logical name ‘userquery’) have been retrieved and filtered by Id to remove duplicates, the next step would be to create the system views. For creating the new system views, with the logical name ‘savedquery’, I had pre-created a list of attributes which allowed me to map the relevant data from personal view to system view. This needed to be done as the entities of both views differ in number of attributes.

After running the console application, the views for all Users were recreated as system views. In the environment I used to test this, my User was the only User with a personal view created.

image

The screenshots above and below show the view “My Contact View” being duplicated as a system view.image

The console application can be used to clean-up the unnecessary personal views once they have been converted into system views.