Searching for NOT empty values in LMS
While I was conducting a workshop on implementing custom search selectors, one of the participants asked if it was possible to search for users where email address, for example, is NOT Empty? (you’ll notice that the capacity to search on emails that ARE empty is in the product already).
Answer: Yes, absolutely! There are two ways in which we can do this. The first, and simplest
option, is to user a wildcard with the “Contains” operator. The second, and more time consuming
option, is to add a new operator to the specific field.
In this blog, we will explore these two solutions to the question raised.
Solution A: Use Wildcards
First, we need to agree that searching for something that is not empty should (and will) yield the same result as searching for something that contains any value. Simply rephrased, “Not Empty” is synonymous with “Contains something”. If we can agree to that, proceed to the next steps.
Let’s make sure wildcards are enabled in your instance. Navigate to the Search properties page.
System Admin » Configuration » System Configuration » SEARCH
Scroll down until you locate the following lines:
# This configuration allows the enabling of wildcard characters to be used in searches (_ for single and % for multiple). enableSingleCharacterWildCard=true enableMultipleCharacterWildCard=true
A default installation of LMS will have both of those settings set to false. In order for this solution to work, you must set enableSingleCharacterWildCard=true. You may opt to also set the enableMultipleCharacterWildCard=true as well, but it is not required for this solution. If these settings are already set to true, you can continue with the following steps.
|*NOTE: Using Wildcards for searching is a fairly common request during implementation, so it is entirely possible that your implementation consultant (SuccessFactors, or 3rd Party) enabled these prior to your original go-live date.|
TIP: While you are here on this SEARCH properties page, you may also want to consider adding this line:
(Its unrelated to the solution here, but this will make all your search selectors default to “Contains” instead of “Starts with”)
Searching using Wildcards by example
Let’s use the following list of email addresses as our users. We can use the “Contains” operator with our newly implemented wildcards.
Email Contains …
|email@example.com||Email addresses that contain the letter “bo” (in that
sequence) followed by anything else, no matter how
many characters follow the initial sequence.
|firstname.lastname@example.org||Email addresses that …
|email@example.com||Email addresses that
Solution B: Add an Operator in the dropdown list
The second option, which may have been the more desirable, is also the most labor intensive solution. If we navigate to the following location:
System Admin » Configuration » Search Selectors » USER (for this particular example)
Edit this search selector. Scroll down until you find the criteria for Email Address. Add (copy & paste) these 4 lines of code.
criteria.EmailAddress.criterionUI.matchOptions.OP_NOTNULL.enabled=true criteria.EmailAddress.criterionUI.matchOptions.OP_NOTNULL.order=7.0 criteria.EmailAddress.criterionUI.matchOptions.OP_NOTNULL.value=OP_NOTNULL criteria.EmailAddress.criterionUI.matchOptions.OP_NOTNULL.label=label.IsNotEmpty
If you are using this job aid to modify a different field, you’ll need to adjust the highlighted code to the field name you are modifying. The remaining code should remain the same. When done, click “Apply Changes”.
Searching using “is not empty” by example
Now let’s go back to the Users Search screen. When you add Email Address to the Search Criteria, you’ll see that there is a new operator “is not empty”. You can ignore the box that now appears. Leave it blank if you are using this new operator.
As you can imagine, this solution would be specific to the Search Selector type (in this case, USER), and specific to the field you are searching (EMAIL ADDRESS). If you wanted to implement this solution in all fields, you would have to repeat the above process for all fields, in all search selectors.
For this reason, you may want to consider Solution A as the more viable option!