Projects:Selector/Default Filter Expressions
Contents |
Overview
The New Selectors provide an easy way to define selectors using the Application Dictionary (AD) without coding. The Default Filter Expression is the way to define expression that will be used by the selector data-source for filtering information.
Note: The changes will be associated with the Issue 13458
Technical Details
Requirements
- Must be easy to write (with a known syntax) - JavaScript in evaluated in the server side is the choice
- It should be possible to use request parameters in the filter expression (inputs from the HTML form)
- It should be possible to access Session attributes
- It should be possible to access the current context (OBContext)
- Some common check should be provided by the API
Preliminary API
// Document related functions OB.isPosted(); // returns true/false if the document is posted OB.isProcessed(); // returns true/false if the document is processed OB.isSalesTransaction(); // returns true/false based on the type of window // Data from Window/Tab OB.getWindowId(); // returns a string with the record ID of the window OB.getTabId(); // returns a string with the record ID of the tab OB.getCommandType(); // returns the type of command // Accessing the context OB.getContext().getUser().id; // gets the current user record ID based on the context OB.getContext().getCurrentClient().name; // gets the current client name // Accessing the HTTP session OB.getSession().getAttribute('#AUTOSAVE'); // access the HTTP session and get an attribute // Accessing the HTTP request OB.getParameters().get('inpParamName'); // Returns the String value of the inpParamName request parameter
Check all public getters of this class OBBindings
Filter Expression at Selector level
The HQL where clauses defines a fixed where that is applied always when fetching data from the database. With the new 'Filter Expression' we can add dynamic HQL where clause that can be applied only in some cases, e.g. Always filter Business Partner for type 'customer' when is a Sales Transaction.
Example
if(OB.isSalesTransaction() === null) { ""; } else if (OB.isSalesTransaction() == true) { "e.customer = true"; } else { "e.vendor = true"; }
Default Expression at Selector Field level
The default expression is also a JavaScript expression that can use the same OB object API, that defines a default value for field in the selector. Depending on the definition of the field, the user can remove the that default value in the selector grid popup.
Example
Suppose that you are defining that you want to always filter by Business Partner type 'customer'.
- Define the Selector Field
- Add the property customer
- Add Default expression
true
Example 2a
Suppose that you want to filter the description field of the product selector in Sales Order Lines with the value from the Sales Order (header) description.
- Mark the 'Description' field in the c_order table as 'Stored in session'. This will cause the system to store the current value of that field in the HTTP-session with a key of windowID + "|DESCRIPTION".
- Recompile the 'Sales Order' window
- Define the Selector Field
- Add the property description
- Add Default expression
OB.getSession().getAttribute('143|DESCRIPTION');
Example 2b
The use case of this is very similar to Example 2a. But instead of a default Filter we'll use the 'Dynamic Filter Expression' to apply the filter directly so the user cannot remove it in this case. Also we enhance the example by not embedding the needed windowID as a constant but retrieve the current window id in the expression to make the selector transparently work with more than one window.
![]() | Note: The example still needs the description field to be marked as 'Store in Session' for each window the selector should be used in. |
- Mark the 'Description' field in the c_order table as 'Stored in session'. This will cause the system to store the current value of that field in the HTTP-session with a key of windowID + "|DESCRIPTION".
- Recompile the 'Sales Order' window
- Define the Selector Field
- Add the property description
- Add Filter Expression
"e.description = '" + OB.getSession().getAttribute(OB.getWindowId() + '|DESCRIPTION') + "'"