CRM 4.0 Master Schema Management and Customization Change Control

 Recently I found a CRM 4.0 Schema comparison tool that I find makes life much easier when I’m playing the role of Schema Master.  Managing schema changes is in my opinion a arduous and very manual process.  It is  not advisable to use TFS for schema file comparisons and definitely not for merging, this is because TFS does line by line comparison not XML tag comparisons.  The Customization Comparison Utility lets you compare the customization files between two Microsoft Dynamics CRM systems and the Configuration Data Utility lets you transfer custom configuration data from one Microsoft Dynamics CRM system to another.   You can download the solution file here

The process I recommend for the proper management and change control practices   essential for the ongoing life cycle of a Microsoft CRM Dynamics Organization Database Schema.  The diagram below represents the three typical scenarios that the Schema Master may encounter on a frequent basis.  The three scenarios are Jr. Developer or Third Party Developer interactions, Senior Developer Interactions and Multi-Developer Entity Edits.  Using the Customization Comparison Utility along with this process will ensure the integrity of your CRM schema and save you from a lot of pain.

  

Master Schema Scenarios

Scenario 1

Under scenario 1 a junior developer or a third-party or outside vendor may need to promote changes to the CRM Master Schema.  In this circumstance the Schema Master would likely be responsible for heavy validation of the schema changes.

1.       The schema items impacted are exported from the developers environment .

2.       The schema items impacted are documented in a standard SharePoint change-log.

3.       The schema export file is checked in to the weekly schema build folder.

4.       The Schema Master reviews the change-log and the may make manual or automated adjustments to the Master Schema.

Scenario 2

Under scenario 2 a senior developer may need to promote changes to the CRM Master Schema in this circumstance would likely be responsible for validation of the schema changes.

1.       The schema items impacted are exported from the developers environment .

2.       The schema items impacted are documented in a standard SharePoint change-log.

3.       The schema export file is checked in to the weekly schema build folder.

4.       The Schema Master reviews the  change-log and the may make manual or automated adjustments to the Master Schema.

Scenario 3

Under scenario 3 multiple developers may need to promote changes to the CRM Master Schema impacting the same entity.  In this circumstance the developers would likely be responsible for creating and validating a single schema export file.

1.       The schema items impacted are exported from the developers environment .

2.       The schema items impacted are documented in a standard SharePoint change-log.

3.       The schema export file is checked in to the weekly schema build folder.

4.       The Schema Master notifies the developers of potential conflicts or collisions.

5.       The developers create a single schema export file and check it in to TFS.

6.       The Schema Master reviews the change-log and the may make manual or automated adjustments to the Master Schema.

The TFS Role

TFS is used as a repository for the incremental schema edits that are proposed as candidates to the Schema-Master.  It’s critical that developers only submit specific entity schema segments rather than the full CRM schema, this is because TFS analyzes code line by line rather than in the XML  tag format the CRM schema model uses.  Also because the environment that the CRM schema is exported from can alter the format and order of the XML.  For these reasons it will be incumbent upon the Schema-Master to understand where the schema segments are coming from and to identify the risks associated with the submitting party.

The SharePoint Role

A standard SharePoint form should be used to capture the schema changes being submitted by each developer.  The SharePoint form should capture at minimum:

               

o    ID Number

o    Entity, Workflow or Role Name

o    Attribute

o    Deployment Comments

o    Impact Analysis Comments

The ID Number shoul

 

d always be references within the TFS check-in comments   and included in the release and deploy notes sent to the Deployment team for each build.

 

 

 

 

 
 
 
 
 
 
 
Advertisements

HTML Editor for Microsoft Dynamics CRM 4.0

Until Microsoft Dynamics 5.0 to comes out the only way to get a HTML or Rich Text editor capability in Microsoft Dynamics CRM 4.0 is to roll your own or use a third party application.  I have had tremendous success using the TinyMCE  editor.  click here to download The editor has a plethora of features available including everything from spell check to word count and is available in a number of  build format and examples including;   jQuery, JavaScript, PHP, .Net and JSP.  I prefer to use the jQuery build for my Microsoft Dynamics CRM 4.0 implementations.

Below I have included a code sample you can use in your custom iFrame.  Accessing the raw HTML source during the CRM onSave event was a little bit tricky, here’s the code for that.

crmForm.all.IFRAME_Accomplishment.contentWindow.tinymce.getInstanceById('elm1').getBody().innerHTML

You can either make a call to the CRM SDK and save this value to the database or use javascript and simply copy to a hidden  nText  field located  directly on the form next to the iFrame.  All we have to do is save and load the raw HTML and the HTML editor does the rest.

I use a FetchXML function to load the raw HTML…

$('#elm1').val(GetContacts());

The GetContacts function simply uses FetchXML to retrieve the value of a nText attribute I have added to the Contacts entity.

Here’s a page that instantiates a HTML editor in a iFrame for use in Microsoft Dynamics CRM 4.0.

<head>
<title>Full featured Microsoft Dynamics CRM 4.0 tinyMCE example using jQuery plugin by ExtremeCRM.net</title>

<!-- Load jQuery -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
 google.load("jquery", "1");
</script>

<!-- Load TinyMCE -->
//****** REMEMBER TO CHANGE THIS PATH TO THE PROPER ISV LOCATION  *******//
<script type="text/javascript" src="../jscripts/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript">
 $().ready(function() {
 $('textarea.tinymce').tinymce({
 // Location of TinyMCE script
 //****** REMEMBER TO CHANGE THIS PATH TO THE PROPER ISV LOCATION  *******//
 script_url : '../jscripts/tiny_mce/tiny_mce.js',

 // General options
 theme : "advanced",
 plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

 // Theme options
 theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
 theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
 theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
 theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
 theme_advanced_toolbar_location : "top",
 theme_advanced_toolbar_align : "left",
 theme_advanced_statusbar_location : "bottom",
 theme_advanced_resizing : true,

 // Example content CSS (should be your site CSS)
 //****** REMEMBER TO CHANGE THIS PATH TO THE PROPER ISV LOCATION  *******//
 content_css : "css/content.css",

 // Drop lists for link/image/media/template dialogs
 template_external_list_url : "lists/template_list.js",
 external_link_list_url : "lists/link_list.js",
 external_image_list_url : "lists/image_list.js",
 media_external_list_url : "lists/media_list.js",

 // Replace values for the template plugin
 template_replace_values : {
 username : "Some User",
 staffid : "991234"
 }

 });

 //Here we load the input textbox named elm1.  This input text box will be overloaded by the tinyMCE editor at runtime.
 //See the GetContacts function below.
 $('#elm1').val(GetContacts());

 });
</script>
<!-- /TinyMCE -->

</head>
<body>

 <form id="form1" runat="server">
 <div>
 <h3>Full featured example using jQuery plugin</h3>

 <p>
 This example shows how TinyMCE can be used from Microsoft Dynamics CRM 4.0  using jQuery. The jQuery plugin will also attach it's self to various jQuery methods to make it more easy to get/set editor contents etc.
 </p>

 <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
 <div>
 <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
 &lt;p&gt;
 This is some example text that you can edit inside the &lt;strong&gt;TinyMCE editor&lt;/strong&gt;.
 &lt;/p&gt;
 &lt;p&gt;
 ExtremeCRM provides developers coding examples, insights, concepts and options for developing customizations for Microsoft CRM 4.0.  The primary contributor, Brenden Smith is a Microsoft MCP and Microsoft CRM 4.0 Lead developer for a federal agency in Washing D.C.  If you would like to be a contributor for extremeCRM.net
 &lt;/p&gt;
 </textarea>
 </div>

 <!-- Some integration calls -->
 <a href="javascript:;" onmousedown="$('#elm1').tinymce().show();">[Show]</a>
 <a href="javascript:;" onmousedown="$('#elm1').tinymce().hide();">[Hide]</a>
 <a href="javascript:;" onmousedown="$('#elm1').tinymce().execCommand('Bold');">[Bold]</a>
 <a href="javascript:;" onmousedown="alert($('#elm1').html());">[Get contents]</a>
 <a href="javascript:;" onmousedown="alert($('#elm1').tinymce().selection.getContent());">[Get selected HTML]</a>
 <a href="javascript:;" onmousedown="alert($('#elm1').tinymce().selection.getContent({format : 'text'}));">[Get selected text]</a>
 <a href="javascript:;" onmousedown="alert($('#elm1').tinymce().selection.getNode().nodeName);">[Get selected element]</a>
 <a href="javascript:;" onmousedown="$('#elm1').tinymce().execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
 <a href="javascript:;" onmousedown="$('#elm1').tinymce().execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>

 <br />
 <input type="submit" name="save" value="Submit" />
 <input type="reset" name="reset" value="Reset" />
 </div>
</form>
<script type="text/javascript">
if (document.location.protocol == 'file:') {
 alert("The examples might not work properly on the local file system due to security settings in your browser. Please use a real webserver.");
}
</script>
</body>
</html>

How to Programmatically Create a Microsoft Word Document from Dynamics CRM

Recently I had a need to create a Microsoft Word document and dynamically populate it from data in CRM.  Microsoft Word can be invoked from JavaScript using the ActiveXObject .  This first example shows a very basic application of the concept.  Create a blank document , add a report title then add some body  text.  In my application I call the JavaScript from a toolbar button added with the ISV.config file.  For more information on adding buttons that call javaScript see Calling JavaScript from Microsoft CRM  Toolbar Buttons

// Start a new instance of Microsoft Word

var MsWord = new ActiveXObject(“Word.Application”);

// Create a new document

MsWord.Documents.Add();

//Carriage Return

MsWord.Selection.TypeParagraph();

//Report Name

MsWord.Selection.TypeText(crmForm.all.new_name.value);

//Carriage Return
MsWord.Selection.TypeParagraph();
//Carriage Return
MsWord.Selection.TypeParagraph();

//Memo field from CRM containing paragraphs of text

MsWord.Selection.TypeText(crmForm.all.new_body.value);

//Show Microsoft Word

MsWord.Visible = true;

 

To create a new document using a Microsoft Word Template do this:

msWord.Documents.Add(“http://myserver:5555/documentTemplate.dotx&#8221;);

To add text to a specific Microsoft Word form field first create a Word template and add a field to it using the developer toolbar then use this code:
msWord.ActiveDocument.FormFields(“Text1”).Result = crmForm.all.new_name.value;

Obviously you can take this much further, in my application I use a AJAX call to a web service to get related CRM records.  I also lock all the fields so their content can’t be modified by the user.  What the user can do is add content to the document which may include HTML content.  The need to generate a report but then add custom content was the genesis for this feature.

Here’s a article about creating fields in Microsoft Word.  Click Here

Creating a CRM 4.0 test/training organization from your production organization and or Recovering a CRM organization database

 

This article will also help with the following scenarios:

  • You want to move the Microsoft Dynamics CRM databases to another Microsoft SQL Server and Microsoft SQL Server Reporting Services server in the same domain. Additionally, you want to leave the Microsoft Dynamics CRM Server on the existing server.
  • You want to redeploy the Microsoft Dynamics CRM deployment that includes the Microsoft Dynamics CRM server within the same domain or to another domain.
  • You want to move the Microsoft Dynamics CRM Server or one of the Microsoft Dynamics CRM server roles. However, you want to leave the SQL Server and SQL Server Reporting Services server intact.

  Requirements

  • SQL Server Management Studio
  • CRM 4.0 Deployment Manager
  • CRM Enterprise Server License
  • CRM Deployment Administrator Permissions
  • SQL Server Administrator Permissions
  • An existing backup of your CRM database

 

Procedure

Restore SQL Database

  1. On the CRM SQL Server navigate to: Start -> All Programs -> Microsoft Dynamics CRM -> Deployment Manager
  2. Click “Connect” to open a connection to the SQL server

     

  3. Right click the “Database” folder and select “Restore Database”

     

  4.  In the “To database” field enter your database name (Note: It is a best practice to name your database with a “_MSCRM” to help distinguish this database from others on that server)

     

  5. Select “From Device” and click the browse button
  6. Click the “Add” button and select the backup of the CRM database that you wish to restore. Click “OK” to select the backup file.

     

  7. Click “OK” to accept your selections.
  8. Check the “Restore” checkbox next to the Database that you wish to restore, and click the Options link in the left hand column. 
  9. Check “Overwrite the existing database” and click the “OK” button to restore the backup file

     

  10. Once complete you will be notified via the following screen.

Import the CRM Organization

  1. On the CRM Server navigate to: Start -> All Programs -> Microsoft Dynamics CRM -> Deployment Manager

      

  2. With Deployment Manager open, navigate to Organizations to get a listing of the current Organizations available in CRM. 

     

  3. Click the “Import Organization” link in the right hand column to start the process of importing a CRM Organization. 

     

  4. On the “Import Organization Wizard” enter in the name of the SQL server, select the newly restored database and click “Next” 

     

  5. Enter the name of the Organization as you want it to appear in CRM and click “Next” 

     

  6. Enter the name of the SQL Reporting Server and click “Next”

     

  7. Select Auto-map users and click “Next”

     

  8. Make any adjustments as necessary and click “Next”

     

  9. Review the requirements screen and click “Next”

     

  10. Click the “Import” button to begin the import of the Organization
  11. After complete click the “Finish” button to close the wizard

Additional Notes:

The import process will automatically attempt to add all the necessary Active Directory group membership for each user that listed in the CRM SystemUserBase table. This step of the process can be lengthy depending on the total number of users in your production CRM organization, and often times it may seem as if the process has hung. A simple yet manual way to monitor the status during this operation is to compare the deployment manager logs with the listing of users in the SystemUserBase table. The import process will process each user, as they are entered in the table, and will write out a log entry for each user that it has processed. The log for the deployment manager is located in:

%USERPROFILE%Application DataMicrosoftMSCRMLogscrm40dmsnapin.log

Although this process will create a separate CRM organization with a point in time snapshot of your company’s customizations as well as its data, it will not allow you to test the deployment of Rollups or other hot fixes. If you are looking to obtain this capability, you will need to setup a separate environment in which you can install a separate copy of CRM. With such a scenario, it is always important to take into consideration, the licensing ramifications of all the software involved (CRM, SQL, Windows, etc). However, if you are simply attempting to setup a duplicate environment where you can train new users or test out new customizations before introducing them into production, this procedure should fully meet your needs.

Routinely companies need the ability to utilize a training or test Microsoft Dynamics CRM 4.0 environment that operates on a similar set of data as their Production deployment. With CRM 4.0 we can achieve this goal by making use of its multi-tenancy capabilities, or the ability to have multiple CRM Organizations. 

Additional help 

How to move the Microsoft Dynamics CRM 4.0 deployment 

Deployment Manager: Import Organization vs. Edit Organization 

Configure a Microsoft Dynamics CRM organization for database mirroring …

Microsoft CRM 4.0 Look and Feel Kit

I notice confusion out there about CSS styles to achieve a native CRM look and feel, for reasons I’m not sure of many folks can’t find the CSS template provided in the CRM SDK which can be downloaded here. Additionally the CSS template that is included by Microsoft doesn’t have much in it, for example there aren’t any CSS styles for grids.

For those of you new to CRM what were really discussing here is iFrames embedded in to your CRM entity form page so the need to match up to CRM to present seamless integration and a clean user interface is important.

I’m going to post the CSS template and images I use in my projects and as I add more styles to it I will update it from time to time.

Click here to download the CRM Look and Feel Kit

Monitoring your Microsoft Dynamics CRM Infrastructure with System Center Operations Manager 2007

Introduction

For any organisation, Systems Availability is crucial to the business and business continuity. Because of the nature and complexity of a CRM Architecture, it is vital to understand the current state of its various components and computers. The entire CRM Architecture can be centrally managed and monitored using System Center Operations Manager 2007 (SCOM), a Dynamic Systems Initiative from Microsoft to help support and be more effective and efficient, thereby saving time and money. The use of SCOM takes guess work out of the support equation, by identifying the root cause of an issue and providing the appropriate solution. As a predictive product it also provides alerts on unforeseen potential problems, enabling proactive support. In this document we discuss the use of SCOM to manage and monitor the CRM architecture comprising of Windows 2003 server, Microsoft SQL Server 2005 or 2008, Microsoft Exchange Server 2003 or 2007, Microsoft Internet Information Server IIS 6 and 7, BizTalk Server 2006, Microsoft Dynamics CRM 4.0, Windows XP, 2000, Vista, Microsoft Office 2007 and custom .Net applications

 SCOM alerts are based on real world problems and solutions developed by domain experts and Windows error reporting is linked to latest resolution knowledge. For illustration purposes the diagram below shows the Asynchronous Service Architecture, a small part of the CRM 4.0 Architecture. The Asynchronous architecture is monitored in the SCOM deployment for CRM 4.0.

  

 SCOM Solution for a Dynamics CRM 4.0 Architecture

Microsoft Dynamics CRM 4.0 architecture can be complex, depending on deployment. To ensure that all the CRM 4.0 components are functioning properly requires a robust support infrastructure. Microsoft System Center Operations Manager is a software solution that meets the need for end-to-end service monitoring in the enterprise. Deploying SCOM is key to effective support for any organisation that values its technology investment, and takes systems availability and uptime seriously.

SCOM components

Operational Database consists of operational data and configuration data for a management group. A Root Management Server is used for configuration management. Management Agents discover, collect, analyse and manage servers’ and clients’ alerts so as to resolve issues and can also wake failed systems. A Reporting Server provides reports for the management group and is displayed in the SCOM console.

Agentless Exception Monitoring extends monitoring to operating systems and applications. It configures error-reporting clients to redirect their reports to the management server providing information on failure and available solutions. An Audit Collector, found on the management server, provides information on security of managed computers from audit enabled agents. In DMZ configurations, a Gateway Server can be used for agents beyond a firewall or found in Non Trusted Domains.

Deploying SCOM

To setup SCOM OpmMgr and RMS databases, SCOM is deployed on a MS SQL Server where the Action, SDK and Service Accounts are specified. A webconsole is deployed specifying the SQL instance, the database name and SQL Listening port, plus provide relevant accounts. With installation complete, an Administrator has to logon to the SCOM server to complete the setup by configuring Discovery and select the managed objects in addition to configuring computers and devices to manage, and importing management packs[1].

Operations Manager 2007 Reporting is setup by installing the data reporting data warehouse and reporting server for reports and dashboards. It is recommended to install the Data Warehouse and Reporting Server on separate servers. A SQL Server Instance is used for the Audit Collection Service and Audit Collection Database setup and enablement.

SCOM Monitoring

A SCOM Monitor looks at different application aspects, known as Object Types, consisting of system devices or services with one of three operational states: healthy, warning or failure. A Distributed Application Designer is built on Service Oriented Monitoring and is easy to configure using a graphic designer. It can also be used to monitor ports and IP addresses of given systems. It also handles Line of Business Applications.

Roles have to be created to manage the SCOM system. Roles are integrated with Active Directory and they can manage tasks authorised for specified roles.

Notifications can be delivered individually via Email, Pager, Instant Messaging, Session Initiation Protocol, Short Message Service support (SMS) and SMTP via the Notification Device Wizard.

SCOM can be integrated with AD for Security Discovery and Agent Management enabling agent deployment and configuration automatically. The SCOM Discovery Wizard feature uses LDAP identify devices in the Directory to manage agents automatically. The MOMADAdmin tool is used to integrate with AD by creating an admin access point with the ability to specify exclusions through the ADSI Edit[2] tool.

To setup Agentless Exception Monitoring, requires configuring the Customer Experience Improvement Program (CEIP) and Error alert routing, transmission settings (through HTTP/S or with SSL with authentication preferences) and Error Crash Behaviour. These alerts can be forwarded to Microsoft and Microsoft will provide available information to solve the issue or in crash cases Microsoft will investigate the issue further.

SCOM Management Features

Through the monitoring space, administrators are able to see in Real-Time the state of systems and or services. Through the health explorer administrators can see the events that are not healthy and can then take corrective action to fix the problem using diagnostics and recovery features found in the management packs. Administrators can work with reports, creating reports for customers etc. and report on planned and unplanned operations and much more. Reports can also be specific, providing information on specific issues.

SCOM 2007 has an excellent and customisable knowledgebase known as Company Knowledge. This knowledgebase is an invaluable resource that provides information on root causes of issues and how they can be resolved. The Company Knowledge is editable, allowing for the addition of company related issues and how they have been resolved.  

 

Company Knowledge is used to capture the steps required to resolve an alert in an OpsMgr installation.  When paired with the Product knowledge (which provides application developers knowledge on the causes and suggested resolution steps for an alert), the two help any operator with the best steps they can take to resolve an alert. Product Knowledge is embedded in a rule or monitor.

 

The power of SCOM lies in the End-to-End visibility of the health and performance of the CRM architecture. This powerful feature empowers support staff to have a complete view of their supported environment, with access to easily accessed information on how to resolve issues affecting their CRM environment in case of an IT issue. They are empowered to take proactive action regarding issues before users can start calling or before systems actually fail, ensuring short Mean Time To Identify (MTTI) and Mean Time to Repair (MTR).

Figure 2 SCOM monitoring in a CRM Architecture

Organisations that have successfully deployed System Center Operations Manager 2007 testify to the ability to provide efficient support and avoiding time wasting extensive manual investigations that can give support a bad name.  Many have deployed SCOM and integrated it with their Helpdesk systems. This integration facilitates the automatic generation of tickets or calls, leading to a significant reduction in waste of support staff effort used to manually create, update and manage tickets or support Calls.

A Microsoft Dynamics CRM (Customer Relationship Management) 4.0 system is built on a three tier Enterprise Architecture consisting of; Client, Application and Data.  SCOM is able to monitor the health and performance of these systems and their applications, easily providing service level monitoring that allows the support team to meet their operational level agreements. Because CRM can be web-enabled, SCOM has the capability to monitor several URLs at any one time and provide real-time data on connectivity status.

Note

SCOM has the capability to monitor non Microsoft technology through Operations Manager Connector Framework. It does this through the bi-directional synchronised partner connector solutions that connects to the third party management packs.

Microsoft Dynamics CRM 4.0 Management Pack

At the time of writing, there is no SCOM Management Pack for Microsoft Dynamics CRM 4.0. However, Microsoft Dynamics CRM 4.0 can be managed using SCOM, by converting the MOM 2005 Management Pack for CRM[3]. This particular management pack monitors the CRM Architecture including:

  1. CRM Asynchronous Processing services.
  2. World Wide Web Publishing
  3. Microsoft Dynamics CRM Deletion Service
  4. Microsoft Dynamics CRM databases

 

Deploying SCOM 2007 provides support staff with an easy-to-use monitoring environment to monitor corporate servers, applications, and clients. This coverage gives staff a full view of the organisation’s systems, something that allows support staff to provide pro-active solutions to issues before they happen, enabling them to proactively maintain and reduce resolution times for any issues that may affect overall availability and performance of the CRM system.

 Microsofts SCOM site can be found here

Working With CRM 4.0 Data Types and Form Controls

Boolean

Specifies a field  that displays one check box or two radio buttons. The Boolean field type is one display option for bit type attributes. The other option is list. The list option uses the Picklist field type.

Note   Changing the formatting options of a bit attribute is done on the form, not in the attribute definition like other attributes. Changing the formatting option from a check box or two radio buttons to a list will change the way that you access the values in the form, potentially breaking your code.

The following properties are available:

Boolean properties Type Description
{Field}.DataValue Boolean or Null Get/set property. The original value is left unchanged if the new value cannot be parsed.
{Field}.DefaultValue Boolean Get property. Returns the default value for the field.

 

Example

The following code example shows how to set a field of type Boolean.

crmForm.all.SOME_BOOLEAN_FIELD_ID.DataValue = true;
 
crmForm.all.SOME_BOOLEAN_FIELD_ID.DataValue = false; 

 

Customer

A Customer field represents a type of Lookup where either an account or contact is a valid type of record.

The following properties are available:

Customer or Regarding properties Type Description
{Field}.DataValue   Specifies an array of lookup objects. For the Customer field this array always has a length of one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.

 

Example

The following code example shows how to use a Customer field type.

var customer = new Array();
customer = null;

// This gets the lookup for the attribute customerid on the Opportunity form.
customer = crmForm.all.customerid.DataValue;

// If there is data in the field, show it in a series of alerts.
if (customer[0] != null)
{
   // The name of the customer.
   alert(customer[0].name);

   // The GUID of the customer.
   alert(customer [0].id);

   // The entity type name of the customer.
   alert(customer[0].typename);
}

 

DateTime

A DateTime field can be formatted to show both the date and time, or the date only. The following properties are available:

DateTime properties Type Description
{Field}.DataValue Date or Null Get/set property.The original value is left unchanged if the new value cannot be parsed.
{Field}.TimeVisible Boolean Get property.This property specifies if the time is to be shown.

 

Example

The following code example shows how to use a field of type DateTime.

var oDate;
var oToday;

oDate =  crmForm.all.scheduledend.DataValue;
if (oDate == null) {
    oDate = new Date();
}

oToday = new Date();
oDate = oToday;
oDate = oDate.setHours(17,0,0);

if (oDate.TimeVisible)
{
   alert("The time is visible.");
}
else
{
   alert("Only the date is visible; the time is hidden.");
}

crmForm.all.scheduledend.DataValue = oDate;

 

Duration

Duration fields are presented as a picklist giving the user a selection of time options from 1 minute to 3 days. But the actual value of a duration field is an integer. If a user types an integer into the field or your code sets the value of the integer representing minutes, the field will convert that value into a more user-friendly unit of measurement. For example, 420 will be displayed as 7 hours.

The following properties are available:

Duration properties Type Description
{Field}.DataValue integer or Null Get/set property.The duration can be set to Null. The original value is left unchanged if the new value cannot be parsed.

 

Example

The following code example shows how to use a field of type Duration.

var iMinutes = 60; crmForm.all.SOME_DURATION_FIELD_ID.DataValue = iMinutes;
 
 
 

E-mail Body

This field type appears in the E-mail activity form. The following properties are available:

E-mail body field methods Type Description
{Field}.DataValue String Used to get the HTML stream for the e-mail body.

Remarks

The HTML stream that defines the DataValue for an e-mail body field is read-only. The DataValue is not available to be read in the OnLoad event.

Example

The following code example shows how to use a field of type E-mail body.

var oField = crmForm.all.SOME_EMAILBODY_FIELD_ID;

alert(The field's HTML is: " + oField.DataValue);

 

 

Float

The following properties are available:

Float properties Type Description
{Field}.DataValue float or Null Get/set property. The original value is left unchanged if the new value cannot be parsed.
{Field}.Min Integer Get property. Returns the minimum allowed value.
{Field}.Max Integer Get property. Returns the maximum allowed value.
{Field}.Precision Integer Get property. Returns the number of digits allowed. This is a value between 0 and 5.

 

Example

The following code example shows how to use a field of type Float.

var oField = crmForm.all.SOME_FLOAT_FIELD_ID;

var iValue = 1976.1102;

// Set the precision of the value.
var oNumber = new Number(iValue);
iValue = oNumber.toPrecision(oField.Precision);

if (iValue < oField.Min)
{
   iValue = oField.Min;
}
else if (iResponse > oField.Max)
{
   iValue = oField.Max;
}

oField.DataValue = iValue;

 

Integer

The following properties are available:

Integer properties Type Description
{Field}.DataValue Integer or Null Get/set property. The original value is left unchanged if the new value cannot be parsed.
{Field}.Min Integer Get property. The minimum allowed value.
{Field}.Max Integer Get property. The maximum allowed value.

 

Example

The following code example shows how to use a field of type Integer.

var oField = crmForm.all.SOME_INTEGER_FIELD_ID;

var iValue = 1000;

if (iValue < oField.Min)
{
   iValue = oField.Min;
}
else if (iValue > oField.Max)
{
   iValue = oField.Max;
}

oField.DataValue = iValue;
 
 

Lookup

A Lookup field type represents the relationship attribute on the related entity. The valid type for the lookup is established in the relationship. Although Lookup is frequently used as a generic term, there are different types of lookups and technically Lookup is the most restrictive kind of field type. Unlike Customer or Regarding, only one entity type is valid in a lookup. Unlike PartyList, only one reference is stored in the field. A lookup field is defined by using the following attributes:

Attribute Type Description
id String The GUID of the item. Required for set.
type Integer Deprecated. The object type code.
typename String The entity name of the item. Required for set.
name String The name of the item to be displayed. Required for set.
data   Any other data. Optional for set.

The following properties are available:

Lookup properties Type Description
{Field}.DataValue An array of lookup objects Get/set property.For lookups this must be an array with the length of one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.

Example

The following code example shows how to read values from a field of type Lookup.

var lookupItem = new Array;

// This gets the lookup for the attribute primarycontactid on the Account form.
lookupItem = crmForm.all.primarycontactid.DataValue;

// If there is data in the field, show it in a series of alerts.
if (lookupItem[0] != null)
{
   // The text value of the lookup.
   alert(lookupItem[0].name);

   // The GUID of the lookup.
   alert(lookupItem[0].id);

   // The entity type name.
   alert(lookupItem[0].typename);

}

Example

The following code example shows how to set values in a field of type Lookup. This example shows how to set the parent account lookup field on the account form.

//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
   lookupItem.typename = 'account';
   lookupItem.name = 'A Bike Store';
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.parentaccountid.DataValue = lookupData;

Memo

Memo represents a multiline text box using the ntext attribute type. The following properties are available:

Memo properties Type Description
{Field}.DataValue A reference to a string object Get/set property.
{Field}.MaxLength Integer Get property.The maximum length of the string.

 

Example

This field is used in the same manner as a String Type.

 
 

Owner

A Owner field represents a Lookup where the linked record can be any record type that can be presented in the field.

The following properties are available:

Regarding properties Type Description
{Field}.DataValue   For the regarding field type this is an array with a length of one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.

Example

The following code example shows how to use a field of type Owner.

var lookupItem = new Array;
lookupItem = null;

// This gets the lookup for the attribute regardingobjectid on the Task form.
lookupItem = crmForm.all.ownerid.DataValue;

// If there is data in the field, show it in a series of alerts.
if (lookupItem[0] != null)
{
   // The text value of the lookup.
   alert(lookupItem[0].name);

   // The GUID of the lookup.
   alert(lookupItem[0].id);

   // The entity type name.
   alert(lookupItem[0].typename);
}

PartyList

A type of Lookup that allows for multiple references to records of multiple types of entities to be set in a single field. A PartyList is typically found on e-mail activities to represent the To, Bcc and cc fields. A PartyList is defined by using the following attributes:

Attribute Type Description
id String The GUID of the item. Required for set.
type Integer Deprecated. The object type code.
typename String The entity name of the item. Required for set.
name String The name of the item to be displayed. Required for set.
data   Any other data. Optional for set.

 

The following properties are available:

PartyList properties Type Description
{Field}.DataValue An array of lookup objects Get/set property.For PartyLists this must be an array with the length of at least one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.
 
 

Picklist

A picklist contains several options. Each option has the following attributes:

Attribute Description
DataValue The index value of the selected option.
Text The text of the picklist option.

The following properties and methods are available:

Picklist properties and methods Type Description
{Field}.DataValue string Get/set propertyGet returns a string representation of the value of the selected option. You can use the method parseInt() to safely convert this to an integer value.

Set changes the selection to the value specified.

{Field}.SelectedText string Get propertyReturns the string value of the selected option.
{Field}.GetSelectedOption option Picklist optionReturns a Picklist option.
{Field}.Options array of picklist options Get/set propertyGet returns an array of Picklist option objects.

Set defines a new set of options, specified by an array of Picklist option objects.

{Field}.AddOption(Text, DataValue) option Used to add an option to the end of the current control’s collection.Text – a string value to be displayed in the option.

DataValue – an integer value that represents the index of the option.

Text and DataValue cannot be Null.

Data is used for storing arbitrary data on the picklist object.

To define valid options, you must modify the Attribute definition by using the Customization tools or the metadata APIs. You should not create new picklist options programmatically in form event code. Manipulating the Options array is the most common solution to ensure valid picklist data.

{Field}.DeleteOption(value) integer Used to delete the option specified by value from the control’s option collection. Does nothing if the option does not exist.
{Field}.DefaultValue integer Get/set property.Get returns the default value for the picklist.

Set specifies the default value for the picklist.

Remarks

All the valid picklist options are defined in the Microsoft Dynamics CRM Metadata. When a record is saved with an invalid picklist option selected the field will be set to the default value and the invalid data will be lost.

There are two supported methods for retrieving the current selection for a picklist field as shown here.

The following returns the text value of the selected picklist item.

crmForm.all.(picklistitem).SelectedText

The following returns the index of the selected picklist item.

crmForm.all.(picklistitem).DataValue

Example

The following code example shows how to use a field of type Picklist. Note that when you add an option to a Picklist, the option must already exist in the set of possible options.

var oField = crmForm.all.SOME_PICKLIST_FIELD_ID;

// Capture the fourth option
var oOption = oField.Options[4];

// Show how many options are available
alert("Original length :"+ oField.Options.length);

// Set the field to the first option by value
oField.DataValue = 1;

// Show the text for the first option
alert(oField.SelectedText);

// Remove the fourth option
oField.DeleteOption(4);

// show the new length
alert("New length :"+ oField.Options.length);

// Restore the fourth option
oField.AddOption(oOption.Text, oOption.DataValue);

// Show the restored length
alert("Restored length :"+ oField.Options.length); 
 

Regarding

A Regarding field represents a Lookup where the linked record can be any record type that can be presented in the field.

The following properties are available:

Regarding properties Type Description
{Field}.DataValue   For the regarding field type this is an array with a length of one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.

 

Example

The following code example shows how to use a field of type Regarding.

var lookupItem = new Array;
lookupItem = null;

// This gets the lookup for the attribute regardingobjectid on the Task form.
lookupItem = crmForm.all.regardingobjectid.DataValue;

// If there is data in the field, show it in a series of alerts.
if (lookupItem[0] != null)
{
   // The text value of the lookup.
   alert(lookupItem[0].name);

   // The GUID of the lookup.
   alert(lookupItem[0].id);

   // The entity type name.
   alert(lookupItem[0].typename);
} 

StringThe following properties are available:

String properties Type Description
{Field}.DataValue A reference to a string object Get/set property.
{Field}.MaxLength Integer Get property.The maximum length of the string.


Example

The following code example shows how to use a field of type String.

var oField = crmForm.all.SOME_STRING_FIELD_ID;

var sValue = "String that might be too long.";

if (sValue.length > oField.MaxLength)
{
   sValue = sValue.substr(0, oField.MaxLength); 
}

oField.DataValue = sValue;

Grab those lookup values

CRM uses the Primary-Attribute (not to be confused with primary key) for many UI features and functions such as the Associated Views and the Lookup View and the default field for Primary-Attribute is Name.  Unfortunately you can’t have a lookup field or picklist for your Primary Attribute so in the example below even though we select a Trip from the Trips lookup the Name (primary attribute) would need to be filled in manually. 

 In this example imagine you have an Entity called Trips and an entity called Trip Packages.  A Trip Package is related to a Trip and it is a required value.  When you select a Trip from the Trip lookup you want to set the value of the Primary-Attribute/Name so that when Trip packages are searched for they will always contain the name of the base Trip.

 The solution is simple but I’ve seen some wild examples that are much more complex.

Here’s the one line of code to be added to the lookup field controls OnChange Event.

crmForm.all.new_name.DataValue = crmForm.all.new_authorid.DataValue[0].name;

 You could easily concatenate other fields to the Name/ Primary-Attribute as well.  I might add trip date and sponsor name for example.  I would use the same code with the appropriate control names to grab those lookup values:

crmForm.all.new_name.DataValue = crmForm.all.new_sponsorid.DataValue[0].name + crmForm.all.new_authorid.DataValue[0].name + crmForm.all.new_tripdate.DataValue;

 I know we can make this example more elegant with the use of variables and string functions but let’s leave it simple for easy digestion.

 Happy coding!

Display a CRM 4.0 PickList Display-Value in Reports and Queries

Microsoft CRM 4.0 stores picklist display values within the MetadataSchema in the StringMap table.  When creating custom reports or quieries a custom Scaler-Function is needed to show the picklist display vale.  To do this I wrote a simple function shown below called MapPickList that can be called in a SQL query to return a picklist displayvalue.

This example shows the CRM Contact table with a custom attribute called ShoeSize

SELECT     LastName, FirstName, dbo.MapPickList(‘contact’, ‘ShoeSize’, ShoeSize) AS DisplayValue

FROM  Contact

The output would look like this:

LastName            FirstName           DisplayValue
—————————————————————-
Smith                    Mark                     12.5
Estes                     Lowell                   10
Sue                        Jones                    7

And here is the SQL function.

CREATE FUNCTION MapPickList

(

/******Name of the CRM Entity we are querying******/

@entity varchar(50),

/******Name of the CRM Attribute we are querying******/

@attribute varchar(50),

/******The picklist int value stored by CRM******/

@value int

)

RETURNS varchar(500)

BEGIN

DECLARE  @return varchar(500)

SET @return = (SELECT StringMap.Value AS DisplayValue

FROM StringMap INNER JOIN MetadataSchema.Entity ON StringMap.ObjectTypeCode = MetadataSchema.Entity.ObjectTypeCode

WHERE (StringMap.AttributeName Like @attribute) AND (StringMap.AttributeValue = @value) AND (MetadataSchema.Entity.Name Like @entity))

return @return

END