Tuesday, July 31, 2012

Friday, July 27, 2012

Getting the Text Value of an OptionSetValue Using LINQ in Microsoft Dynamics CRM 2011

I have seen some interesting things historically when trying to get at the text value of an OptionSetValue in code.  Many times this means making a metadata RetrieveAttributeRequest or something of that nature to get the metadata for the OptionSet.  This is pretty cumbersome in many instances, but the other day I saw an interesting way of doing this put out in a forum question here.

The basics are as follows.

1. Use CrmSvcUtil.exe (comes with the SDK) to get a context that you can use with the CRM LINQ provider.

2. Use LINQ to pull the entity attribute FormattedValues for a specific attribute of type OptionSetValue.  The example below is pulling based on a specific entity ID so it pulls the specific text value of the optionset in this instance.


var strstringvalue = (from ca in context.CreateQuery<CampaignActivity>()
        where ca.ActivityId == campaignResponse.new_CampaignActivityId.Id
        select ca.FormattedValues["new_campaignactivitytype"]);



This should help somebody out. :) - Happy Friday!

Thursday, July 19, 2012

Kick Your Business Up a Notch: All The Way To AWESOME!!

Learn how you can kick your business up a notch with Microsoft Dynamics.  This is a pretty cool little AD campaign by Microsoft that hopefully can be used to introduce Microsoft's "Dynamic Business" concept that I think could really help a lot of people.

Fun YouTube Video Promotion: http://www.youtube.com/watch?v=iO8HZLR8-G4

The Meat and Potatoes: http://www.microsoft.com/en-us/dynamics/dynamic-business.aspx

- Check it out!

Thursday, July 12, 2012

How to Build an HTML/JScript Configuration Web Resource for Microsoft Dynamics CRM 2011


Web Resources can be used to create an interface to allow end-users to easily configure your solution after it's been installed.  This is ideal for storing keys and other sorts of registration or configuration information related to the solution.

Download the Sample here: http://code.msdn.microsoft.com/Sample-HTMLJScript-172cd74e

For step-by-step instructions on how to install a configuration page (this one is already installed) and work with it from an end-user standpoint you can visit Mahender Pal's blog here:
http://mahenderpal.wordpress.com/2011/07/26/step-by-step-adding-configuration-page-in-solution-ms-crm-2011/

Building the Sample

1. First you must unzip the download file and install the included zip file SampleConfiguredSolution_1_0.zip
2. Next you must Import and Publish the  SampleConfiguredSolution_1_0.zip into your Microsoft Dynamics CRM 2011 instance.  Your instance can be On-Premise or Online.


Description

After you install the solution there are only two main components worth noting.  
1. A custom entity used to store configuration data.  I chose to use a custom entity instead of an XML file or other mechanism due to the ease of securing and manipulating the data.  The data is easy to secure because, as a custom entity, it uses the standard role-based security already included in CRM and by default will only be available to administrators.  The data is also easier to manipulate because if stored as an XML web resource it is stored in the content attribute of the webresource entity.  This means that you have to follow these steps to work with the data.
- un-encode the content attribute (it is stored as a base-64 encoded string)
- parse the XML 
- update the values
- re-encode the attribute data in base-64
- make an update call
It's just more complicated.

2. An HTML webresource that includes jscript that contains the GUI for working with the configuration data and also has jscript web service calls wired up inside that facilitate saving and retrieving the data.
The logic is easy:
When page loads it checks for a configuration record with a specific name.  If it finds the record it will load the data into the GUI.  
When the update button is pressed it checks if the record existed or not and creates it if it didn't exist otherwise it will update the record.


Source Code Files

  • SampleConfiguredSolution.zip - Download Zip File
  • SampleConfiguredSolution_1_0.zip - CRM 2011 Unmanaged Solution File

Tuesday, July 10, 2012

Using the Dynamic Type in Silverlight to Easily Access The Client-Side API in Microsoft Dynamics CRM 2011

This is a neat little trick to be able to easily work with the client-side API in CRM 2011 from within Silverlight using the "Dynamic" type.

1. Add a reference to Microsoft.CSharp from the .NET tab in your project.

2. Now you are ready to go.  The Dynamic type is one that allows you to write your code but allow it to not be evaluated until runtime.  This means that the compiler won't throw an error if your syntax is bad though so you will want to be precise.

The example given below illustrates getting the form type and verifying it is an update form and then if it is we are calling a function from a jscript webresource attached to the form (that is part of a namespace).  I also embedded a little call to get the entity ID in there also.  It makes it hard to remember that you are working in C# sometimes.

dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
var formType = xrm.Page.ui.getFormType();
string strFormID = xrm.Page.data.entity.getId();
if (formType == 2)
{
    dynamic sdk = (ScriptObject)HtmlPage.Window.GetProperty("SDK");
    sdk.SAMPLES.TriggerActionsRequest();
}


- I hope this helps!

Sunday, July 8, 2012