Search Component - Filter

  • 7
  • Question
  • Updated 3 years ago
  • Answered
LOVE the new Search component.  Is there a way to limit the results the users will get from a certain object?  For example... I am build a CPQ proof of concept.  I'm using the Search Component to search on the Products object, but I only want my users to see Product results where Active = TRUE.  (As well as other filters.)  Possible?
Photo of Chandra V

Chandra V, Champion

  • 7,720 Points 5k badge 2x thumb

Posted 5 years ago

  • 7
Photo of Zach McElrath

Zach McElrath, Employee

  • 55,610 Points 50k badge 2x thumb
Chandra, this is not currently supported via the Page Composer, but once we release Banzai Update 2 (at the end of this week), there will be a supported way to do this via XML, which I'll share with you now even though it is not going to work until you get Banzai Update 2:

1. Click to edit your page's XML (bottom right corner of Page Composer)
2. Find your Search component within the <components> XML by looking for "search", you should see something like this:

3. Now find the <object> node corresponding to the Product2 object, and find the </fields> tag. Immediately after the </fields> tag, and copy in the following XML:

   <condition type="fieldvalue" field="IsActive" operator="=" value="true" enclosevalueinquotes="false"/>

4. Save your page.
5. Wait till Banzai Update 2 comes out, and then try your search again --- assuming that your searching on the Product2 object, your records should be limited to just those Product2 records where the IsActive field is true.
Photo of Pat Vachon

Pat Vachon, Champion

  • 46,084 Points 20k badge 2x thumb
Just had the same issue. Needed to filter and was going to add this as an idea.

Implemented and works as expected.


Photo of Griffin Brown

Griffin Brown

  • 2,858 Points 2k badge 2x thumb
This reply was created from a merged topic originally titled Search Box - Adding a WHERE condition to the SOSL Query.

It'd be helpful for me to specify a WHERE statement to the SOSL query in the search component. This seems fairly straight foward given SOSL syntax.

FIND {Joe Smith}
IN Name Fields
RETURNING lead (name, phone Where createddate = THIS_FISCAL_QUARTER)<br>
Here's my XML:
<search uniqueid="sk-1pOUMT-385" soslfields="Name Fields" limit="5">                                 
                                    <object id="Phrase_Template__c" displaytemplate="{{Text_English__c}} {{Phrase_Type__c}}">
                                          <field id="Phrase_Type__c"/>

Is there a way to write in a WHERE statement in <field id="Phrase_Template__c"/>?
Photo of Zach McElrath

Zach McElrath, Employee

  • 55,580 Points 50k badge 2x thumb
Griffin, I merged your question into Chandra's question - this can be done right now via XML, as described above.
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,798 Points 5k badge 2x thumb
Hey Zach ... I tried this and it works well. I have two other wishlist items for Search and was wondering if these can be tackled in the XML also:
  1. Can we rename an object in the results? e.g. I've put a condition on the Account object results so that they only return clients. Would be great to rename the label for that object to Clients.
  2. Can we reuse the same object twice with different conditions? e.g. I want to search for clients as above, but I also use the Account object to store service providers, so I want to reuse Account, but with a different condition and label.
Photo of Griffin Brown

Griffin Brown

  • 2,858 Points 2k badge 2x thumb
Did we ever find out the answers on this?

Also, can we do the following:

  • Sort the results
  • Filter based on a value from a model
e.g. <condition type="fieldvalue" field="Goal_Discipline__c" enclosevalueinquotes="true" value="{{$}}"/>
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 18,596 Points 10k badge 2x thumb
I used Zach's XML and it worked like a charm. However, perhaps future versions of search could be based on a model instead of the object directly. Then you could build a model with all kinds of conditions and sorting.
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,808 Points 5k badge 2x thumb
"perhaps future versions of search could be based on a model instead of the object directly"

I agree. That would be ideal, and consistent with the rest of Skuid.
Photo of

  • 2,042 Points 2k badge 2x thumb
Hi I always want to return a specific record from Account plus what ever user searches for. So I added two account object under Return objects. For one of them, I added

                                                                                                                           <condition type="fieldvalue" field="Name" operator="=" value="Add New Company" enclosevalueinquotes="false"/>

But searching is not working. How can I fix it? Thanks!