How to Prefix a value to the query string for a field
The requirement is to add a prefix to the query string entered by the user on the Last Name field on the Contact BC. Example: If user enters A* , the contacts returned should be of form HD B*. In this example, the prefix is HD.
Follow the below steps to implement this trick of adding the prefix value to the query string on a particular field in the BC.
Go to Contacts BC -> Edit Server Scripts and write the below line of code in Pre_Query event of the BC.
function BusComp_PreQuery ()
var qstr = this.GetSearchSpec(“Last Name”); // If User entered A* on UI, in Watch Window it returns: LIKE B*
var len = qstr.length; // returns the length of the entered string
var str = “HD”; // HD is the Prefix value. Change this value as per the requirement
if(qstr != “”)
var a = qstr.substring(0,6); // Break the Search string. In Watch Window it returns: LIKE
var b = qstr.substring(6,len); // Break the Search string. In Watch Window it returns: B*
var expr = a + str + ” ” + b; //Form a new expression, In Watch Window it returns: LIKE HD B*
this.SetSearchSpec(“Last Name”, expr);
Compile the BC and launch the Siebel Client Application.
Say a user has entered value called B* on the Last Name field on the UI as shown below:
When User presses Enter key the expected result is below:
SQL generated in spool will show as below: