Monday, March 07, 2011

MSCRM 4.0: Customize the Lookup View of Role Entity

In my current project, I developed a custom workflow called IsUserInRole which helps determine whether a user is in a particular role. It all worked fine, until we deployed the workflows to our UAT and production environments.

Let me try to explain what the problem is. The custom workflow has a lookup input parameter for Role entity which allows the business user to specify a CRM role to test whether the current user or a specified user has that particular role. In our local VPC development environment, we tried to keep everything simple, we only had a root business unit for the CRM installation. So the IsUserInRole workflow can show all the roles in the CRM system without any confusion. But in our UAT and production environments, we had more than one business unit, so all the roles that we created in the root business unit were automatically copied to the child business units, which caused significant confusion for the CRM workflows that used IsUserInRole workflow. When we were trying to use CRM lookup to pick a role, we got something like the following screen shot, which you could see a number of roles in the same name but they actually belonged to different business units. This created a challenge for us, as we could easily pick a wrong role, so that the custom workflow would not function in the way that we expected.
CRM Default Role Lookup View
I first thought this would be an easy job, as CRM allows us to define almost any views. But when I fired up the customization page of Role entity, I realized that is a totally different story, CRM didn't provide a way that allows me to customize any view for role entity. I went on thinking about using exported role entity customization xml file, but I hit a wall again as I noticed that the role entity customization XML file was almost empty, it had no view information or whatsoever in the export xml file.

After a little struggle, I realized that I might be able to take a shortcut by directly typing in CRM view customization page's URL with the view's ID. So I took a peek of CRM database using the following SQL query.
 SQL Query for Role Lookup View
After running the above SQL script, I have got the view's ID. What I need to do next is, go to a customizable entity, and double click one of its views to launch a view customization page, and I press Ctrl+N key to launch the page in a new window so that I can have IE address bar. Then I replace the ID parameter in the address bar with the view ID I have just got from previous SQL query, so that I have a URL in the following format.


As soon as I have the above URL typed in and hit my browser's Go button, I get just a regular view customization screen. Whew!
Edit CRM Role Lookup View
You might already know, as soon as we get to this point, the rest is fairly easy. I added "Business Unit" column to the view using "Add View Columns" button on the right, and then published all CRM customization changes. After that, I came back to my custom workflow and I noticed that I could see the Business Unit column in the lookup view. 
CRM Role Lookup View with Business Unit Column
I believe this technique not only applies to the views of CRM role entity, you should also be able to use it to customize almost all views of core CRM entities such as Team, Queue, Workflow, etc., if you ever happen to have this kind of needs.  

Hope this helps.

P.S. I would have used a different solution for my custom workflow if I foresaw the problem of using Role lookup that I have mentioned, but I do hope this blog post helps if you ever come across similar needs in your project.

No comments:

Post a Comment