IBM FileNet P8, Version 5.2.1            

Creating a Search Function Definition

A CmSearchFunctionDefinition object specifies the handler implementation of a custom search function. The following Java™ and C# examples show how to create two CmSearchFunctionDefinition objects. One of the objects references a handler that is implemented with Java and the other object references a handler that is implemented with JavaScript.

For the first CmSearchFunctionDefinition object that is created, the handler that is implemented with Java is contained within a code module. The CodeModule object is retrieved and set on the CodeModule property of the CmSweepAction object.

For the second CmSearchFunctionDefinition object that is created, the search function handler is implemented in JavaScript, requiring that the script is set on the ScriptText property of the object.

Start of change
Restriction: You cannot use custom search functions in a stored search. You can use these functions in ad hoc or background searches in a SELECT list only.
End of change

Java Example

// Create search function definition for Java handler.
CmSearchFunctionDefinition sfd = Factory.CmSearchFunctionDefinition.createInstance(os, "CmSearchFunctionDefinition");

// Get CodeModule object with Java component.
CodeModule cm = Factory.CodeModule.getInstance(os, "CodeModule",
                new Id("{30261747-0000-C817-91CA-46A3B56BF558}") ); 

// Set CodeModule property.
sfd.set_CodeModule(cm);

// Set ProgId property with fully qualified name of handler class.
sfd.set_ProgId("sample.actionhandler.DateConversionFunctionHandler");

// Set other properties and save.
sfd.set_DisplayName("sfd_Java");
sfd.set_DescriptiveText("Specifies Java search function handler");
sfd.save(RefreshMode.REFRESH);

// Create search function definition for JavaScript handler.
CmSearchFunctionDefinition sfdJs = Factory.CmSearchFunctionDefinition.createInstance(os, "CmSearchFunctionDefinition");

// Set ProgId property to script type identifier.
sfdJs.set_ProgId("Javascript");

// Call method to read script from a file, and set the script text on the definition object.
String inputScript = readScriptText();
sfdJs.set_ScriptText(inputScript);

// Set other properties and save.
sfdJs.set_DisplayName("sfd_JavaScript");
sfdJs.set_DescriptiveText("Specifies JavaScript search function handler");
sfdJs.save(RefreshMode.REFRESH);

C# Example

// Create search function definition for Java handler.
ICmSearchFunctionDefinition sfd = Factory.CmSearchFunctionDefinition.CreateInstance(os, "CmSearchFunctionDefinition");

// Set ProgId property with fully qualified name of handler class
sfd.ProgId = "sample.actionhandler.DateConversionFunctionHandler";

// Get CodeModule object with Java component.
ICodeModule cm = Factory.CodeModule.FetchInstance(os, 
                 new Id("{30261747-0000-C817-91CA-46A3B56BF558}"), null); 

// Set CodeModule property.
sfd.CodeModule = cm; 

// Set other properties and save.
sfd.DisplayName = "sfd_Java";
sfd.DescriptiveText = "Specifies Java search function handler.";
sfd.Save(RefreshMode.REFRESH);

// Create search function definition for JavaScript handler.
ICmSearchFunctionDefinition sfdJs = Factory.CmSearchFunctionDefinition.CreateInstance(os, "CmSearchFunctionDefinition");

// Set ProgId property to script type identifier.
sfdJs.ProgId = "Javascript";

// Call method to read script from a file, and set the script text on the definition object.
String inputScript = readScriptText();
sfdJs.ScriptText = inputScript;

// Set other properties and save.
sfdJs.DisplayName = "sfd_JavaScript";
sfdJs.DescriptiveText = "Specifies JavaScript search function handler.";
sfdJs.Save(RefreshMode.REFRESH);


Last updated: October 2015
customSearchFunctions_snip2.htm

© Copyright IBM Corporation 2015.