Thursday, May 19, 2011

Scriptless Solution: Email Validation with regexp

Requirement: Email Validation on email fields in siebel.

The solution for the requirment is described below. The idea is to use regular expression in DVM and validate regular expression in short business service script.


Solution:
Step1: Create a Business Service as below.
This is required as there is no function to evaluate regexp in DVM
BS Name: Email Validation BS

function ValidateEmailAddress(Inputs, Outputs)
{
try{

var strEmailAddr = Inputs.GetProperty("EmailAddress");
var strPattern = Inputs.GetProperty("Pattern");
var strRetVal = "INVALID";
Outputs.SetProperty("Result", strRetVal);
if(strEmailAddr.search(strPattern) != -1)
strRetVal = "VALID";
else
strRetVal = "INVALID";
Outputs.SetProperty("Result", strRetVal);
}
catch(e)
{
Outputs.SetProperty("Result", strRetVal);
throw e;
}
}


Step 2: Create a DVM Rule.

  • Create a Validation Message with below values.
    • Message Code: TEST-101
    • Message Level: Account
    • Message Source : Email
    • Message Text: Incorrect Email Format
  • Create a Ruleset with below values.
    • Name: Email Validation
    • Business Object: Contact
    • Business Component: Contact
  • Create an Argument in Arguments Tab.
    • Argument Name: Pattern
    • Default Value: /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,5})$/g
  • Create a Rule Expression in Rules Tab.
    • Sequence: 1
    • Name: Contact Email Validation
    • Expression: InvokeServiceMethod("Email Validation BS", "ValidateEmailAddress", "Pattern='"+[&Pattern]+"',EmailAddress=eval([Email Address])", "Result")<>"INVALID"
    • Business Component: Contact
    • Apply To: Current Record
    • Return Code: TEST-101
    • Immediate Display: True (In Rule Detail Tab)
  • Activate Rule by clicking Activate Button.
Step 3: Create a Runtime event
Create a Runtime event to call above DVM Rule.How to create a Runtime event is described in my previous post.

You will see error message displayed shown below when you try to save email with incorrect format.

You can give any regular expression to validate email in DVM Argument as "Pattern". So It is only required admin effort to modify the value at run time which doesn't required SRF change.

3 comments:

  1. I try this but for some reason i always get the same error and i use a correce email. Do i have to set my BS somewhere in the configurations ?

    ReplyDelete
  2. This is such a great resource that you are providing and you give it away for free. www.verifications.io

    ReplyDelete

Siebel Open UI is released ...!!!

Hi Guys, The most awaited feature of Siebel, called Open UI is released. This new feature Open UI is available in new Siebel patch 8.1.1....