Saturday 2 July 2011

CRM 2011 – Get Optionset labels in Silverlight 4 using SOAP endpoints


Recently, I need to fetch the optionset values of one of the custom entities named as ‘Candidate’. It has one a custom attribute like job type. The job type is having values like Permanent, Temporary, Part time, on contract. I developed a Silverlight 4  data grid control to show the all candidates with some search criteria. By design, using OData service reference you can’t fetch the metadata of CRM entity. So here only get the related values of the optionset like 1 for Permanent, 2 for Temporary and so on. So, if you would like to show the label you have to choose the SOAP endpoint service reference.

Now, to start with SOAP endpoint development I referred a very useful link of MSDN. I am sharing the same here, 

With the help of this link you can setup the required service reference and the utility classes to use messages or methods of CRM SDK.

Below is the code snippet which I have used to fetch the labels using SOAP endpoints in my candidates.xaml.cs file. You can use the same code by just passing the entity and attribute names. I hope this will be helpful. 

   1: /// <summary>
   2: /// Get options set labels for specified entity's optionset type attribute
   3: /// </summary>
   4: /// <param name="entityName"></param>
   5: /// <param name="attributeName"></param>
   6: private void GetOptionSetLabels(string entityName, string attributeName)
   7: {
   8:     OrganizationRequest request = new OrganizationRequest();
   9:     request.RequestName = "RetrieveAttribute";
  10:     request["EntityLogicalName"] = entityName;
  11:     request["LogicalName"] = attributeName;
  12:     request["MetadataId"] = Guid.Empty;
  13:     request["RetrieveAsIfPublished"] = true;
  15:     IOrganizationService service = SilverlightUtility.GetSoapService();
  16:     service.BeginExecute(request, new AsyncCallback(OnGetOptionSetLabelsComplete), service);
  17: }
  21: /// <summary>
  22: /// Retrieve the resutls
  23: /// </summary>
  24: /// <param name="result"></param>
  25: private void OnGetOptionSetLabelsComplete(IAsyncResult result)
  26: {
  27:     //Get the original query back from the result.
  28:     OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);
  30:     if (response != null && response.Results.Count > 0)
  31:     {
  33:         //Get the actual optionset meta data
  34:         OptionSetMetadata optionSetMetadata = ((EnumAttributeMetadata)(response.Results[0].Value)).OptionSet; 
  36:         //Set the metadata object in required field
  37:         Common.JobTypeOptionSetMetadata = optionSetMetadata;
  38:     }
  39: }

Monday 30 May 2011

CRM 2011: Change sitemap customization

Recently I worked upon a project where in I required updating the sitemap customization to have altogether new areas to be replaced with the default CRM areas and subareas of sitemap. I found some interesting things while doing such customization changes, so I would like to share the same here in this post.
1.       You can give a title to areas and the subareas, suppose I want to change the title of default Sales area from Sales to “Property Sales”, just add a title attribute as shown below.

<Area Title=” Property SalesId="SFA" ResourceId="Area_Sales" Icon="/_imgs/sales_24x24.gif" DescriptionResourceId="Sales_Description">

The same attribute could be added for any of the subareas to have different titles.

2.       Setup the custom entity as subarea link,

<SubArea Title="Property Information" Id="nav_property_information" Entity="new_property" />

As shown above, you can setup the custom entity as link. Only the Id is the required attribute. This will show the default view of an entity on click of the above link.

Note: You can use either URL or Entity while setup a custom entity link, if by mistake you keep both the attributes in any of subarea, your CRM server will crash, and you could not browse anything for that particular organization. Also you cannot revert back as there is no “Settings” area available to be browsed now. So I would suggest you to have backup of your database before you import the updated sitemap customization/solution.

Visit below link to know more about the rest of the attributes of subarea.

3.       Use the character entity reference, decimal character reference, and hexadecimal character reference for markup-significant and internationalization characters, as well as the rendering of such characters in your browser.

For example, suppose you want a subarea title as “Sales, Marketing & Services”. Use “&amp;” entity in place of ‘&’ character. So now your title will be “Sales, Marketing &amp; Services”.

Visit below link for more help.

Wednesday 13 April 2011

Deselect, remove or exclude the associated systemuser entity record(s)

Whenever you have 1:N relationship with systemuser entity, you will not be able to delete or remove the systemuser record from Users associated view. It is by design. So to remove that you must have a lookup attribute of related entity on your systemuser form and need to delete that record from lookup and save the form. Let's understand with an example.

Suppose I have 1:N relationship between Marketing List and systemuser entities. So now I have Users associated view in left navigation of Marketing list record. Let's add an existing user for this marketing list record. There is no direct way to remove, delete or exclude the added user record. So for deselecting this user record we could have a lookup of Marketing list entity on systemuser form. Add the Marketing list lookup attribute on systemuser form, publish it. Now back to Users associated view, double click the user record, delete the marketing list record from the lookup on user form. It will refresh the parent grid and removes the user record.

I hope this will be helpful.

Tuesday 15 March 2011

Metadata Browser for Microsoft Dynamics CRM 2011

To get the new metadata browser you must:
1. Download the SDK.
2. Install the SDK.
3. Import the located in the SDK at SDK\Tools\MetadataBrowser\.
Visit below link for more details

Update Rollup 16 for Microsoft Dynamics CRM 4.0

The Microsoft Dynamics CRM Sustained Engineering (SE) team released Microsoft Dynamics CRM 4.0 Update Rollup 16 on Thursday, March 10, 2011.