Create a table filter configuration using scripting

You can create a filter with scripting mapped to a table configuration to improve search results.

Before you begin

Role required: admin

Procedure

  1. Navigate to Contextual Search > Table Configuration.
  2. Select a table configuration on which to create the filter (for example, Customer Service Case, Incident, etc.).
  3. From the Filter Configurations related list, click New.
  4. Fill in the Search resource field on the Table Filter Configuration form with the resource to be searched (for example, knowledge, social, etc.).
  5. Click the Active check box.
  6. Click the Enable advanced filtering using script check box.
  7. Add script content to the Script for Filter section to configure the filter.
  8. Click Submit.

Example

(function buildFilter(current) { 
// 'current' is a GlideRecord instance of the 'Search context table'. 
// The return is an encoded query that will be executed on the 'Search resource table'. 

/*
The sample script below addresses the following scenario: 
   - The 'Search context table' is of type Case [sn_customerservice_case] and has a field called 'asset' that refers to the table 'alm_asset' 
   - The 'Search resource table' is of type Knowledge [kb_knowledge] and has a field called 'u_product' that refers to the table 'cmdb_model' 
   - Out of the box 'alm_asset' has a field called 'model' that refers to the table 'cmdb_model' 
   - Based on the asset provided in the case, we will derive the 'model', and use that to filter Knowledge Articles for that 'model'. */
 
	 /*
	 var filter = ""; 

	 //Logic to build encoded query filter here. Build filter only if user has entered an "asset" 
	 if(current.asset) { 
		 // u_product is a custom field in Knowledge Table. 
		 filter += "^u_product=" + current.asset.model; 
	 } 

	 return filter; */