GeniusResultAnswer - Scoped
-
- UpdatedJan 30, 2025
- 7 minutes to read
- Yokohama
- API reference
The GeniusResultAnswer API provides methods for creating an answer object in a Genius Result configuration's processor scripts. Answers created with this API define search requests or key-value pair maps that can populate Genius Result answer cards.
You can populate the answer object with query details retrieved from the context of the Genius Result configuration using the GeniusResultContext API.
- If you're scripting in a Genius Result configuration's AI Search request processor field, you need to invoke the setTable() method and one of the setSearchPhrase(), addSearchPhrases(), or setEncodedQuery() methods. All other methods are optional except for addDataMap(), which is not relevant for this use case.
- If you're scripting in a Genius Result configuration's AI Search response processor field, you need to invoke the addDataMap() method. No other methods are relevant for this use case.
sn_ais
namespace identifier. For more information on scripting logic for Genius Results, see Create a new Genius Result configuration.GeniusResultAnswer – addDataMap(Object map)
Defines a Genius Result answer with arbitrary key-value pair fields in your Genius Result configuration's AI Search response processor script. You can utilize any public ServiceNow AI Platform API to generate these fields.
You can add multiple field maps to a single AI Search response processor script by invoking this method more than once. Each field map populates a separate Genius Result answer card.
Name | Type | Description |
---|---|---|
map | Object | Defines an arbitrary set of key-value pair fields for addition to the search query response from AI Search. All field values must be Strings. |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search response processor script adds custom title and URL key-value pair fields to the answer object for display on a Genius Result answer card.
GeniusResultAnswer – addSearchPhrases(Array searchPhrases)
Adds terms to the search query defined in your Genius Result configuration's AI Search request processor script.
Name | Type | Description |
---|---|---|
searchPhrases | Array | Array of arbitrary Strings to add as search terms for the search query defined in your Genius Result configuration's AI Search request processor script. AI Search treats these search terms as if separated by the OR operator. Example: |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search request processor script constructs a search query for records on the User [sys_user] table that contain the terms Beth or Anglin.
GeniusResultAnswer – setEncodedQuery(String query)
Specifies an encoded search query in your Genius Result configuration's AI Search request processor script. Results from this encoded search query are displayed as Genius Result answer cards.
Name | Type | Description |
---|---|---|
query | String | Encoded search query to send to AI Search from your Genius Result configuration's AI Search request processor script. |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search request processor script constructs an encoded search query against the User [sys_user] table. The final query joins together multiple subqueries generated from entities detected in the user's original search query.
GeniusResultAnswer – setSearchLimit(Number searchLimit)
Limits the maximum number of results returned for the search query defined in your Genius Result configuration's AI Search request processor script. By default, the search query returns up to three results.
Name | Type | Description |
---|---|---|
searchLimit | Number | Positive integer value for the maximum number of search results to return for the search query defined in your Genius Result configuration's AI Search request processor script. Values above 3 have no effect. Default: 3 |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search request processor script searches for records from the Catalog Item [sc_cat_item] table that contain the term laptop and returns a maximum of two results.
GeniusResultAnswer – setSearchPhrase(String searchPhrase)
Specifies terms for the search query defined in your Genius Result configuration's AI Search request processor script.
Name | Type | Description |
---|---|---|
searchPhrase | String | Terms to use for the search query defined in your Genius Result configuration's AI Search request processor script. If you want to retain the search terms from the query that triggered the Genius Result configuration, set this parameter to the String value returned by the GeniusResultContext.getOriginalSearchPhrase() method. |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search request processor script constructs a search query for records from the User [sys_user] table that contain the term Anglin.
GeniusResultAnswer – setTable(String table)
Limits the search query defined in a Genius Result configuration's AI Search request processor script to a specific table. The query only returns search results from the specified table as Genius Result answer cards.
Name | Type | Description |
---|---|---|
table | String | ServiceNow AI Platform table name. Only indexed records on this table are returned as results for the search query defined in your Genius Result configuration's AI Search request processor script. |
Type | Description |
---|---|
Boolean | Flag that indicates whether invocation of the method succeeded. Valid values:
|
Example
This AI Search request processor script constructs a search query for records from the User [sys_user] table that contain the term Anglin.
GeniusResultAnswer – spellCheck(Boolean spellCheck)
Specifies whether to perform typo handling auto-correction (spell checking) for the search query defined in a Genius Result configuration's AI Search request processor script.
If you don't invoke this method in your Genius Result configuration's AI Search request processor script, the defined search query inherits the typo handling flag from the search query that triggers the Genius Result configuration.
Name | Type | Description |
---|---|---|
spellCheck | Boolean | Flag that indicates whether to perform typo handling auto-correction for the search query defined in your Genius Result configuration's AI Search request processor script. Valid values:
Default: true |
Type | Description |
---|---|
None |
Example
This AI Search request processor script disables typo handling auto-correction for its search query against the User [sys_user] table.
On this page
- GeniusResultAnswer – addDataMap(Object map)
- GeniusResultAnswer – addSearchPhrases(Array searchPhrases)
- GeniusResultAnswer – setEncodedQuery(String query)
- GeniusResultAnswer – setSearchLimit(Number searchLimit)
- GeniusResultAnswer – setSearchPhrase(String searchPhrase)
- GeniusResultAnswer – setTable(String table)
- GeniusResultAnswer – spellCheck(Boolean spellCheck)