Introduction

The purpose of this blog is to show how to enable search for multi-valued properties in advanced search form in Alfresco. Let’s assume that we are looking for authors and we want to find all the documents created by author John or Mary. This feature allows to do this in single query instead of two queries.

Solution

Multi-valued search is already supported in Alfresco, but requires additional configuration. This can be done by adding additional hidden field to advanced search form. The field should follow the name format prop:{name of the filed with values separated by commas}-mode and defines logical operator that should be used to replace commas.

 <config evaluator="model-type" condition="cm:content">
        <forms>
            <!-- Search form -->
            <form id="search">
                <field-visibility>
 
                    <!-- Author field-->
                    <show id="cm:author" force="true" />
                    <!-- Field to enable multi-value author support-->
                    <show id="prop:cm:author-mode" force="true"/>
 
                </field-visibility>
                <appearance>
 
                    <field id="cm:author" set="document_additional"/>
                    <!-- Use OR logical operator for authors -->
                    <field id="prop:cm:author-mode" set="document_additional">
                        <control template="/org/alfresco/components/form/controls/hidden.ftl">
                            <control-param name="contextProperty">OR</control-param>
                        </control>
                    </field>
 
                </appearance>
            </form>
        </forms>
    </config>

In addition, hidden.ftl form control has to be modified to support providing field value in contextProperty parameter. The changes are presented below:

<#-- Renders a hidden form field for edit and create modes only -->
<#assign fieldValue = "">
<#if field.control.params.contextProperty??>
   <#if context.properties[field.control.params.contextProperty]??>
      <#assign fieldValue = context.properties[field.control.params.contextProperty]>
   <#elseif args[field.control.params.contextProperty]??>
      <#assign fieldValue = args[field.control.params.contextProperty]>
   <#else>
       <#assign fieldValue = field.control.params.contextProperty>
   </#if>
<#elseif context.properties[field.name]??>
   <#assign fieldValue = context.properties[field.name]>
<#else>
   <#assign fieldValue = field.value>
</#if>
 
<#if form.mode == "edit" || form.mode == "create">
   <input type="hidden" name="${field.name}" 
          <#if field.value?is_number>value="${fieldValue?c}"<#else>value="${fieldValue?html}"</#if> />
</#if>