Friday, January 9, 2009

Copy and Paste CRM Picklist Values - Part II

In Part I, I posted a screen capture demonstrating customization of the out-of-the-box edit attribute form in Microsoft Dynamics CRM 4.0. A custom "Edit All" button is displayed when a picklist type is selected which enables the editing of multiple picklist value / label pairs at once. The allows copying and pasting of lists from other data sources when setting up picklists - which can be a time saver - especially when setting up many, or large, picklists.

In this post I'm going to go over setting up the project that you'll need in order to enable this customization. I'm going to assume familiarity with Visual Studio 20005, C#, ASP.NET, and JavaScript. If you're not comfortable with these technologies, I would recommend either using existing workarounds, for example the online XML generator mentioned here, or hiring a CRM consulting firm like HubKey to assist you.

To begin, on your CRM development machine, in Visual Studio, create a new C# class library project and call it AttributesPicklistEditAll. You'll need to add references to the following four Microsoft Dynamics CRM DLLs from your server root folder (e.g. C:\Program Files\Microsoft Dynamics CRM Server) - all paths below will be relative to this root:

\Tools\Microsoft.Crm.dll
\CRMWeb\bin\Microsoft.Crm.Application.Components.Application.dll
\CRMWeb\bin\Microsoft.Crm.Application.Components.UI.dll
\CRMWeb\bin\Microsoft.Crm.Application.Pages.dll

Add a fifth reference to System.Web. (You won't be needing the reference to System.Xml or System.Data).

We're going to be making a change to the default manageAttribute.aspx page so that a new Edit All button is rendered for picklist types. Make a backup of that file, which is in the following location:

\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx

and then add the file as an existing item to your project in Visual Studio.

Once you've added it in Visual Studio, copy it and rename the copy to editAll.aspx
This will be the popup dialog that opens when the Edit All button is clicked. Open the renamed file (editAll.aspx) and remove all of the text.

Rename the default project file class1.cs to EditAll.cs

Add a new item to your project - a JScript file called editAll.js

In the project properties / signing tab, make sure that the assembly to be generated is signed by a strong name key file (e.g. key(.snk)). On the application tab, change the assembly name and default namespace to HubKey.Crm.Web.Tools.SystemCustomization.Attributes

On the project properties / build events tab add the following post-build event commands (assuming here that your server root is "C:\Program Files\Microsoft Dynamics CRM Server") - these commands reset IIS, make a copy of your original manageAttribute.aspx if you haven't already done so, copy (overwriting) the aspx pages and js file to the necessary locations, and then copy the assembly to the GAC:

call iisreset

if not exist "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx.orig" copy "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx.orig"

xcopy "$(ProjectDir)*.aspx" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes" /D /I /Y
xcopy "$(ProjectDir)*.js" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\_static\Tools\SystemCustomization\attributes\scripts" /D /I /Y

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /U "$(TargetPath)"
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /F /I "$(TargetPath)"


You should end up with a solution window that looks like the following:

Long Running Job Status Page

In Part III I'll go over the code that you'll need to support this project.

1 comment:

Guru Prasad said...

Getting error in building the application.
at runing Buildapplication properties

call iisreset

if not exist "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx.orig" copy "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes\manageAttribute.aspx.orig"

xcopy "$(ProjectDir)*.aspx" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\SystemCustomization\Attributes" /D /I /Y
xcopy "$(ProjectDir)*.js" "C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\_static\Tools\SystemCustomization\attributes\scripts" /D /I /Y

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /U "$(TargetPath)"
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /F /I "$(TargetPath)"