We must have used SetSearchSpec and SetSearchExpr many times in our code. But few days back through Amol I came to know about a new method by which we can setup a Sticky Search Spec on Siebel Objects.
By sticky search spec I mean that it cannot be changed from UI or using ClearToQuery in script. That search spec will remain in effect till the time that particular instance of BC is in memory. I will try to explain the use of SetNamedSearch with help of a requirement
To create a dynamic search spec on a PickApplet based on position.
- User wanted to see records of users with particular position in that pick applet
- Flexibility to see combination of positions such as
‘Developer 1’ and ‘Developer 2’
‘Dev*’ or (‘*QA*’ and ‘*Manager*’)
- Flexibility to be able to change it anytime
To provide flexibility to change it anytime, we decided to use LOV’s where user will specify their search expression.
- On Applet load evaluate the conditions
- Query appropriate LOV
- Set the search spec and issue an execute query.
It had the desired outcome but then we found a problem with this. Query button was available on that Pick Applet and user could query which resulted in search spec set through script to be overridden with what user has queried and user was able to see all the records in case he issued a blank query. That is where we decided to use SetNamedSearch
On Applet load we issued an query using SetNamedSearch which resulted in the desired record and user could only query from the resulting records only as this SearchSpec cannot be changed from UI. The code that fulfilled the requirement was like
If(Condition == “Query”)
var Bo = TheApplication().GetBusObject(“List Of Values”);
var Bc = Bo.GetBusComp(“List Of Values”);
var test = Bc.GetFieldValue(“Description”);
var currentBC = this.BusComp();
SetNamedSearch has two arguments Name and SearchExpr
Name: Can be any valid string. Returned if you execute a GetNamedSearch method
SearchExpr: Can be any valid search expression.
Query set by SetNamedSearch is appended to all the queries that are executed after it till the time that BC instance is active once the instance is destroyed NamedSearch is also removed.
Code provided by Amol 🙂