Search
Friday, July 03, 2009 ..:: CRM Weblog ::.. Register  Login
 Phone Validation

Scenario

The code will demonstrate how to develop a client-side verifications for Microsoft CRM events using the Account entity.

Goal Description

You want to validate and display a message on invalid values.

  • When the Phone number is been enter or make modifications, the phone number will be validated. 
  • Validate any number like 000000000,111111111....9999999999, any number with the following code 999-555-9999, for the 7 or 10 digit are code.
  • When the phone number value is one of the demo/dummy numbers a dialog box with the message "Invalid phone number please retry" should appear.
  • When the value is an invalid number for the attribute the phone number attribute will be clear
  • For the correct phone numbers auto-format using the following phone number pattern  (999) 999-9999

Instructions

These steps begin at SETTINGS » CUSTOMIZATIONS » CUSTOMIZE ENTITIES » ACCOUNTS » FORMS AND VIEWS » FORM

  1. On the Account form select the Phone number entity
  2. Click Change Properties and Click Events tab
  3. Select the OnChange event and click Edit
  4. Get the Code from the Downlods web page look for "Microsoft CRM 3.0 Accounts Entity Phone Validation"
  5. Insert the code from the file Phone_Validation_onchange.txt 
  6. Click the Event Enabled check box
  7. Click OK to close the Event Detail properties window
  8. Click OK to Close the Form Properties window
  9. Publish your changes.

 

  

 Extending the Workflow process with .Net Assemblies

The following code example shows a few simple methods you can use to add and subtract from a datetime variable.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Microsoft.Crm.Platform.Workflow
{
   public class BuildIn
   {
      public DateTime AddDateTime(DateTime dt, int years, int months,
                                   int days, int hours, int minutes )
      {
         return dt.AddYears(years).AddMonths(months).AddDays(days)
     .AddHours(hours).AddMinutes(minutes);
      }       public DateTime SubtractDateTime(DateTime dt, int years, int months,
                                       int days, int hours, int minutes )
      {
         return dt.AddYears(-years).AddMonths(-months)
     .AddDays(-days).AddHours(-hours).AddMinutes(-minutes);
      }
   }
}
   


The following shows an example workflow configuration file that corresponds to the sample code.

<workflow.config xmlns="http://microsoft.com/mscrm/workflow/" >
   <methods>
      <method name="Add DateTime"
         assembly="Microsoft.Crm.Platform.WorkflowAssembly.dll"
         typename="Microsoft.Crm.Platform.Workflow.BuildIn"
         methodname="AddDateTime"
         group="Date Time Functions">
         <parameter name="Date Time" datatype="datetime"/>
         <parameter name="Years" datatype="integer" default="0"/>
         <parameter name="Months" datatype="integer" default="0"/>
         <parameter name="Days" datatype="integer" default="0"/>
         <parameter name="Hours" datatype="integer" default="0"/>
         <parameter name="Minutes" datatype="integer" default="0"/>
         <result datatype="datetime"/>
      </method>
      <method name="Subtract DateTime"
         assembly="Microsoft.Crm.Platform.WorkflowAssembly.dll"
         typename="Microsoft.Crm.Platform.Workflow.BuildIn"
         methodname="SubtractDateTime"
         group="Date Time Functions">
         <parameter name="Date Time" datatype="datetime"/>
         <parameter name="Years" datatype="integer" default="0"/>
         <parameter name="Months" datatype="integer" default="0"/>
         <parameter name="Days" datatype="integer" default="0"/>
         <parameter name="Hours" datatype="integer" default="0"/>
         <parameter name="Minutes" datatype="integer" default="0"/>
         <result datatype="datetime"/>
      </method>
      <method name="Execute"
         assembly="Microsoft.Crm.Platform.BulkOperationControlAssembly.dll"
         typename="BulkOperationControlService"
         methodname="Execute"
         group="BulkOperationControl"
         isvisible="0"
         timeout="7200">
         <parameter name="Caller" datatype="caller"/>
         <parameter name="BulkOperationId" datatype="lookup"
                          entityname="bulkoperation"/>
         <result datatype="string"/>
      </method>
   </methods>
</workflow.config>

  

Copyright 2005 CodersOasis.com and HotMediaStudios.net   Terms Of Use  Privacy Statement
Portal engine source code is copyright 2002-2009 by DotNetNuke. All Rights Reserved