Advertisements

Archive

Posts Tagged ‘validation’

JScript validation on Activation/Deactivation of record in CRM 2011

December 13, 2011 3 comments

Hi,

We can perform JScript validation on Activation or Deactivation of  a record in CRM 2011.

We can achieve this by reading event save mode from CRM context (i.e.,CRM returns unique Codes or Numbers for different actions; Example 5 for Deactivation button click & 6 for Activation click).

Note :-  CRM 2011 JScript allows us to pass “Execution Context” as first parameter to Jscript function.

Below are the steps

1) Create a new Jscript file and place below JScript function

// Use the following function on Form Save Event,

// CRM will pass the execution context in function paramter prmContext

function FrmOnSave(prmContext) {

var wod_SaveMode;

if (prmContext != null && prmContext.getEventArgs() != null) {

// “getSaveMode()” returns event mode value (i.e., 5 on Deactivation button click etc…)

wod_SaveMode = prmContext.getEventArgs().getSaveMode();

// 5 will pass on Deactivate button click

if (wod_SaveMode == 5) {

// Write your “Deactivate” validation code here

alert(“Deactivation event fired”);

}

// 6 will pass on Activate button click

elseif (wod_SaveMode == 6) {

// Write your “Activate” validation code here

alert(“Activation event fired”);

}

// Use the code line below only if validation is failed then abort function save event

prmContext.getEventArgs().preventDefault();

}

}

2. Add the JScript file as a webresource to the default solution

3. Register the function on “onsave” event (As below)

JScript event handling on record Activation

JScript event handling on record Activation

Check "Pass execution context as first parameter" checkbox

Check "Pass execution context as first parameter" checkbox

4. Save & Publish

5. Open the record and click on “Activate/Deactivate” button (Refer below screen)

Alert on record activation

Alert on record activation

– Below is the useful post on the same

http://social.technet.microsoft.com/wiki/contents/articles/4122.aspx

Hope it helps 🙂

Advertisements

Email format validation in CRM

October 27, 2011 1 comment

Hi,

The out of the box CRM Email field type does not validate whether the given email is ending with “.com”,”.in”,etc… (Refer below)

  • rajeevpentyala@live  (Its a valid email format as per out of the box CRM Email Type validation)

We can validate all the metrics of Email format by using below steps.

Step 1:-

  • Create a new “Field” (i.e.,new_emailaddress1) of type nvarchar(100)
  • Since the field is normal field, we have to format the field to look like “Email”
  • Place below script in form ‘onload’ event

    var emailTextBox = crmForm.all.new_emailaddress1;

//Set the field style similar to ‘Email’ (i.e., Blue forecolor and Underline)
emailTextBox.style.color = “#0000ff”;
emailTextBox.style.textDecoration = “underline”;

//Attach ‘on double click’ event
emailTextBox.attachEvent(“ondblclick”, openEmail);
function openEmail() { if (emailTextBox.DataValue != null) document.location = “mailto:” + emailTextBox.DataValue; }

Step 2 (Email Validation) :-

  • We can validate email format either in form’s ‘onsave’ event (or) field’s ‘onchange’ event
  • Register below function as per your requirement (i.e.,Either in ‘onsave’ or ‘onchange’)

function ValidateEmail() {
var emailID = crmForm.all.emailaddress1.DataValue;

if ((emailID.indexOf(“@”) > 0 && (emailID.lastIndexOf(“@”) != (emailID.length – 1))) || (1 == 1)) {
if (emailID.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
}
else {
alert(“You must enter a valid e-mail address.”);
crmForm.all.emailaddress1.SetFocus();
event.returnValue = false;
}
}
}

Hope it helps 🙂