29 April 2009

Show both active and inactive records in the lookup view

I had a post about how to return both active and inactive records in the Quick Find View.
People then ask: how to show both active and inactive/deactivated records in the entity's Lookup View?

CRM MVP Batistuta Cai already had a post about a plug-in solution.

If the lookup entity is a system entity, you can also use this technique:

Let's start from an example: you have a custom entity call: MyEntity, you have setup a N:1 relationship between MyEntity and Opportunity, so the user can see an opportunity lookup field on the MyEntity form. Now you want to show users both active and inactive opportunities from that lookup field, all you need to do is put the below code into MyEntity.OnLoad() event:

crmForm.all.new_opportunityid.lookupclass = "alllookups";

The lookup class are controlled via xml files in %ProgramFiles%\Microsoft CRM\Server\ApplicationFiles\
If you take a look at the file: opportunity.xml, you may find a condition like: <condition attribute="statecode" operator="eq" value="0"/>

you can remove the condition, and then use this class, e.g: crmForm.all.new_opportunityid.lookupclass="opportunity"; However it's very much unsupported way(by changing files)! But if you open the file: alllookups.xml, you may find that the opportunity(object type="3") entity doesn't have such condition, so we can use this class to get all opportunities.

09 April 2009

Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit

Thanks Microsoft CRM E2 team to provide this useful Toolkit for CRM developers.

To provide developers with the ability to create and manage on-premise CRM solutions in an integrated Visual Studio environment, the Microsoft Dynamics CRM Engineering for Enterprise (CRM E2) team initiated and sponsored the development of the Microsoft Dynamics CRM Developer Toolkit. The toolkit includes two primary components:

The CRM Explorer
The CRM Explorer complements the CRM
Solution Framework, providing the project factories required to open and build
the solution from within Visual Studio. The Explorer manifests as a window
within Visual Studio 2008 and provides direct access to CRM for creating and
editing business units, security roles, and most importantly, entities. The CRM
Explorer is linked to the solution framework which enables it to intelligently
place generated code into the relevant solution framework project.

The CRM Solution Framework
The CRM Solution Framework is a suite of Visual Studio C# projects that are coupled with CRM Entity customizations and wrapped with extensible MSBuild–based developer builds and daily builds. The Framework contains several “pre-canned” projects for the typical tasks that are required of developers when undertaking most Enterprise-level CRM projects. Several of these projects have an inheritance model that affords simple and intuitive augmentation, which can significantly reduce the time required to “jump start” development of new projects.




Software Requirements
Microsoft Dynamics CRM 4.0
Visual Studio 2008 Professional
Visual Studio Team Explorer
StyleCop 4.3 or later (full installation, including MSBuild Integration files)
.NET 3.5 SP1

Installation:
1. Install the CRM Explorer(under folder \CRM Explorer\setup.exe)
2. Install the CRM Solution Framework(under folder \CRMSolutionFrameworkTemplate\Setup.cmd)
Use command prompt to install: Setup.cmd {InstallDir} {ProjectName} {Project Long Name} {Organization Name}

Configuration:
1. Load the project UKDynamics first(Load project normally), then build the solution.
2. Load the project MyCrmSolution(Load project normally), it will referce the UKDynamics class on the step 1. *[1] *[2]
3. From Visual Studio menu bar, click [Tools], then select the [Connect to CRM Server...], give the information then click [OK] button;
4.From Visual Studio menu bar, click [View], then select the [Other Windows]>>[CRM Explorer] *[3]

*[1] If you get warnings like: The referenced component 'UKDynamics.Instrumentation' could not be found. Then you need to re-add the dll reference(UKDynamics.Instrumentation.dll) from UKDynamics\bin folder.

*[2] If you get errors like: The command ""C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil" /i "C:\Projects\MyCrmSolution\SourceCode\MyCrmSolution\Core\Configuration\bin\Debug\MyCrmSolution.Core.Configuration.dll" /f" exited with code 1. Configuration
It because all assemblies are delay-signed, you can turn off the strong-name verification on the dev environment by using the SN tool from Visual Studio 2008 Command Prompt: SN.exe -Vr *,*
then run IISRESET.exe

*[3] If you get errors when expand the item, like:
Client found response content type of 'text/html; charset=utf-8, but expected 'text/xml'. HttpException 1310
Exception message: Could not load file or assembly 'MyCrmSolution.Core.BusinessProcesses, Version=1.1.0.0, Culture=neutral, PublicKeyToken=2c1937e0898110b2' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
It is the same reason and solution with *[2]


Note: The Toolkit is based on components that were initially developed within the Dynamics CRM MCS team in the UK subsidiary. Those components have been refined over a number of UK-based global engagements.

Important: The Microsoft Dynamics CRM Developer Toolkit currently supports customization of on-premise CRM deployments only. This Toolkit and the accompanying documentation are unsupported and are being provided “as is” by the CRM E2 team to assist developers with managing and extending their on-premise Microsoft Dynamics CRM implementations.