One of the things I get asked a lot about is having different Views on Entities for different users. This is possible using a Plug-In. I’ve attached a sample showing how to change defaults (and hide views) depending on the user’s security role. The plug-in has to be registered for the RetreieveMultiple message on the savedquery entity to be be executed in the post stage (I have also included an export from the registration tool).
In this example I’m setting two different default views depending on whether the user is a Sales Person (My Active Contacts) or a Sales Manager (Active Contacts) and in addition, hiding a view if the user is a Sales Person.
I wrote a little console application that uses the CRM Metadata Service to create a Picklist attribute on the contact entity called country and adds all of the options to it. With a little modification, you can make it create any other picklist attributes..
I got a copy of the list of countries (ISO 3166) from here here
I’ve uploaded the solution to my SkyDrive account, just remember to update the app.config file (fairly straightforward) and also add a reference to the CRM Metadata Web Service and name it MetadataSdk.
About a week ago a colleague of mine told me that he’d been able to use my JS script to retrieve fields from a related record upon the change of a lookup value- which worked exactly as he wanted. However, one of the fields he retrieved was a Picklist value- which was obviously a numeric value and pretty pointless since the field he was displaying the value in was nvarchar.
He had three options;
1) Hard code the text values for each option value in his code (yeah, right!),
2) Create a picklist with the same values (text and numeric) as the source picklist and ensure that his documentation clearly outlines that the two picklists will forever have to kept in sync (umm, no thanks),
3) Perform a web service call to the Metadata service and retrieve the options for the source picklist (!).
var request = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"RetrieveAttributeRequest\">" +
" <MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
" <EntityLogicalName>account</EntityLogicalName>" +
" <LogicalName>accountcategorycode</LogicalName>" +
" <RetrieveAsIfPublished>false</RetrieveAsIfPublished>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/MetadataService.asmx", false);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
var result = xmlHttpRequest.responseXML;
Hope that helps somebody out there!