Ben Walker
  • Blog
  • Blog

Programmatically removing attributes from user views in Dynamics CRM

8/2/2018

0 Comments

 
If you have used an attribute in a saved view in Dynamics, and the attribute is removed from the entity, you will get the following error when you try and access the view:
Picture
ilst it is straightforward to amend the view definition in Dynamics and remove the attribute from the view, we recently had a situation where many users had taken a system view containing the now-deleted attribute as the starting point for their own views, and thus several dozen users had views with the deleted attribute in it. Rather than wait for the support calls to come flooding in when users were presented with an error message which they did not understand, we decided to write a script which would go through each users views and remove the offending attribute.
The process is quite simple:
  1. Using impersonation, loop through each user in the system and query their user views for views containing the attribute.
  2. For each view containing the attribute in question, edit the ‘fetchxml’ and ‘layoutxml’ attributes, removing the references to the attribute
  3. Save the views
Here’s some sample code which would remove two attributes from all views belonging to a particular set of users. Amend the attribute, entities and user filter to tailor to your own requirements.

    
0 Comments



Leave a Reply.

    Archives

    July 2021
    June 2021
    May 2020
    March 2020
    December 2019
    October 2019
    June 2018
    February 2018
    October 2017
    September 2017
    August 2017
    May 2017
    April 2017

    Categories

    All
    Dynamics 365
    Dynamics CRM
    FakeXrmEasy
    LINQPad
    Testing

    RSS Feed

    Author

    Some stuff about me!

Proudly powered by Weebly