Thursday, Aug. 17, 2017

How to parse / prevent input of special characters

Written By:

|

July 24, 2012

|

Posted In:

Requirement:

The requirement is to prevent the input of special characters in such a way that special characters are parsed as soon as user enters them on the UI.
For example:
If user enters value as Contact Last Name as “Davi!d“, then automatically value should be stored as “David” i.e. “!” special character should be removed as soon as user tabs out of the Last name field on the UI.

Solution:

Follow the below steps to implement this requirement using Siebel Script.

1. Go to your Business component and declare a global variable and write the below lines of code in Pre_SetFieldValue event of the Server Script.

a. In declarations section declare a global variable as:
var rightval;

b. function BusComp_PreSetFieldValue (FieldName, FieldValue)
{
if (FieldName == “<BC Field Name>”)
{
var rval = “”;                                                                //declare local variables
var ch;                                                                         //declare local variables
for (var i=0; i<FieldValue.length;i++)
{
ch = FieldValue.charAt(i);                                           //loop around each character
if (Clib.isalpha(ch))                                                    //returns True if char is an alphabetic character from A to Z or a to z; otherwise, false
rval = rval+ch;
}
TheApplication().SetSharedGlobal(“rightval”, rval);                                 //Set a Global variable
}
return (ContinueOperation);
}

2. In the same business component write below lines of code in SetFieldValue event of Service Script.
function BusComp_SetFieldValue (FieldName)
{
if (FieldName == “<BC Field Name>”)
{
var lval = TheApplication().GetSharedGlobal(“rightval”);                                    //Get the value of Global variable
if (lval != null || lval != “”)
{
this.SetFieldValue(“<BC Field Name>”, lval);                                    //Set the field value
TheApplication().SetSharedGlobal(“rightval”, “”);                               //Set the Global variable to NULL
}
}
}

3. Expand the same BC and query the <BC Field Name> field as that queried in the above scripts.
Set the ImmediatePostChanges property of this field as TRUE so that the PreSetField Value event fires as soon as the user tabs out on the UI.

4. Compile the BC.

5.See the expected results as below on the Last Name field :

parse-special-chars1 is changed to parse-special-chars2 as soon as User tabs out of Last Name Contact field.

parse-special-chars3 is changed to parse-special-chars4 as soon as User tabs out of Last Name Contact field.



Share This Article

About Author

Gurdeep

Hi, I am sharing my experience to alleviate beginners with open UI and HI version of Siebel CRM. I work in Sun Life Financials and can be reached via IT Tool box as well. Thanks.

Comments are closed.

Leave A Reply