Creating a JavaScript Search Result Template With the Legacy Interface Editor

Coveo for Salesforce 2.3 - July 2015 

Coveo for Salesforce 1.0.901 - June 2015 

Coveo JavaScript Search Framework 1.0.20 - July 2018 

You can easily create new search result templates using the JavaScript Search Interface Editor by duplicating an existing one.

Coveo for Salesforce 2.26 - July 2016  A newer Coveo JavaScript Search Interface Editor replaces the legacy Interface Editor described in this topic (see JavaScript Search Interface Editor).

Leave out-of-the-box search result templates intact and rather modify copies of them. This way, you can always come back to the out-of-the-box templates to review how they were made.

To create a search result template

  1. In Salesforce, navigate to the Coveo search page for which you want to create a search result template, and then access the Interface Editor (see Accessing the Coveo Legacy Interface Editor in Salesforce).

  2. In the search interface, click anywhere in the search results area to show the Result list parameters in the Interface Editor.

    SFIntV2-InterfaceEditorResultLIst1

  3. In the Interface Editor, under Result List in the Templates bar, click the plus icon Icon-PlusTemplate1.

  4. In the box that appears:

    TemplateEditorAddTemplate1

    1. Select the most appropriate existing template (out-of-the-box or custom) to duplicate for the template that you want to create.

    2. Leave the template name intact, and then click Add Template.

  5. Click the component horizontal bar with a down-arrow to expose the template basic parameters.

    SFIntV2-IntEdtDownArrowBar1

  6. In the Id box, enter the desired name for your duplicated new template.

    SFIntV2-IntEdtTemplateBasic1

  7. In the Condition box, enter a JavaScript condition to be met to apply this template to a search result.

    When your search page contains more than one search result template, this is a very important parameter that determines which template is applied to each search result.

    JavaScript condition explanations and guidelines:

    • Must be a valid JavaScript condition (returning true or false).

    • Should be as specific as possible and mutually exclusive with the condition of other templates to prevent confusion.

    • Typically based on the content of a field, in which case the condition format is typically:

      raw.myfieldname == 'fieldvalue'

      In the condition, raw refers to the object returned to the search interface and contains the field name and value for each search result.

      You can see the field names and values available for a JavaScript Search results by holding Alt and double-clicking a search result. In the Debug screen that appears, look at the content of the Fields section.

      In a browser such as Chrome, you can also see the returned raw object by inspecting your Coveo JavaScript Search interface:

      Chrome-errorAsSuccessRaw

      1. Open the Developer tools (F12 key).

      2. Select the Network tab.

      3. Run a query.

      4. Select the ?errorAsSuccess=1 element.

      5. Select the Response tab and scroll down to see the raw object and its field information for a given search result.

      • You can base your condition on object types.

        For Salesforce Chatter results, the condition would be:

        raw.objecttype =='FeedItem' || raw.objecttype == 'FeedComment'

      • You can base your condition on the source name.

        For Salesforce Knowledge results, when your Salesforce Knowledge source name contains Knowledge, the condition could be:

        raw.syssource = 'knowledge'

      • You can base your condition on the connector type.

        For Jira results, the condition could be:

        raw.sysconnectortype == 'JiraCrawler'

  8. Click Return to save changes.