---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# SentimentAnalyser - Scoped

# SentimentAnalyser - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The SentimentAnalyser script include provides methods to perform sentiment analysis on a string value.

You should use this script include in a script that is treated as an admin-executing script. For example, use the Sentiment Analysis script includein a script action or scheduled job.

To use this class in a scoped application, use the `sn_nlp_sentiment`
namespace identifier. The Sentiment Analysis plugin (com.snc.sentiment_analysis) must be
enabled to access the SentimentAnalyser API.

## SentimentAnalyser - SentimentAnalyser() {#ariaid-title2}

Creates an instance of the SentimentAnalyser class with the default connector
configuration that is used for sentiment analysis.  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();

## SentimentAnalyser - SentimentAnalyser(GlideRecord configGR) {#ariaid-title3}

Creates an instance of the SentimentAnalyser class with the specified connector
configuration that is used for sentiment analysis.
{#SA-SentimentAnalyser_G__table_vzp_jc1_l2b__entry__3}

| Name | Type | Description |
|-|-|-|
| configGR | GlideRecord | GlideRecord object of a connector configuration. |
[Table 1. Parameters]

{#SA-SentimentAnalyser_G__table_vzp_jc1_l2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser(configGR);

## SentimentAnalyser - analyze(String inputText) {#ariaid-title4}

Performs sentiment analysis on the specified text.
{#SA-analyze_S__table_mzl_vfl_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| inputText | String | Text on which sentiment analysis should be performed. |
[Table 2. Parameters]

{#SA-analyze_S__table_mzl_vfl_b2b} {#SA-analyze_S__table_nzl_vfl_b2b__entry__2}

| Type | Description |
|-|-|
| JSON object | Result of the sentiment analysis specifying the status, score, normalised score, sys_id of the relevant connector configuration, and error message. |
[Table 3. Returns]

{#SA-analyze_S__table_nzl_vfl_b2b}  


            var sa = new sn_nlp_sentiment.SentimentAnalyser();
            var result = sa.analyze ("Example string");

Output:

    {"status": "Success", "score": "0.7", "normalizedScore": "0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", "errorMessage":""}

## SentimentAnalyser - analyzeMultiple(Array inputTextArray) {#ariaid-title5}

Performs sentiment analysis on an array of strings.
{#SA-analyzeMultiple_A__table_gxm_gll_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| inputTextArray | Array | Array of text (string) on which to perform sentiment analysis. |
[Table 4. Parameters]

{#SA-analyzeMultiple_A__table_gxm_gll_b2b} {#SA-analyzeMultiple_A__table_hxm_gll_b2b__entry__2}

| Type | Description |
|-|-|
| JSON Array | An array that gives the result of the sentiment analysis performed on multiple texts specifying the status, score, normalized score, sys_id of the relevant connector configuration, and error message. |
[Table 5. Returns]

{#SA-analyzeMultiple_A__table_hxm_gll_b2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var result = sa.analyzeMultiple (["Example string1","Example string2"]);

Output:

    [{"text": "I am happy","result": {Success", "score": "0.7", "normalizedScore": "0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", "errorMessage":""}},{"text": "I am not happy","result": {Success", "score": "-0.7", "normalizedScore": "-0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", "errorMessage":""}}]

## SentimentAnalyser - analyzeMultipleWithLanguage(Array inputTextArray, String
language) {#ariaid-title6}

Performs sentiment analysis on an array of strings in the specified
language.
{#SA-analyzeMultipleWithLanguage_A_S__table_qxx_h4m_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| inputTextArray | Array | Array of text (string) on which to perform sentiment analysis. |
| language | String | Language for the input text. This can very for different sentiment services. |
[Table 6. Parameters]

{#SA-analyzeMultipleWithLanguage_A_S__table_qxx_h4m_b2b} {#SA-analyzeMultipleWithLanguage_A_S__table_rxx_h4m_b2b__entry__2}

| Type | Description |
|-|-|
| JSON Array | An array with the result of the sentiment analysis performed on multiple texts of the mentioned language, specifying the status, score, normalized score, sys_id of the relevant connector configuration, and error message. |
[Table 7. Returns]

{#SA-analyzeMultipleWithLanguage_A_S__table_rxx_h4m_b2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var result = sa.analyzeMultipleWithLanguage (["Example string1","Example string2"], "en");

Output:

    [{"text": "I am happy","result": {Success", "score": "0.7", "normalizedScore": "0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", "errorMessage":""}},{"text": "I am not happy","result": {Success", "score": "-0.7", "normalizedScore": "-0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", "errorMessage":""}}]

## SentimentAnalyser - analyzeWithLanguage(String inputText, String language) {#ariaid-title7}

Performs sentiment analysis on a specified text and language.
{#SA-analyzeWithLanguag_S_S__table_jgj_xjl_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| inputText | String | Text on which to perform sentiment analysis. |
| language | String | Language for the input text. This can vary for different sentiment services. |
[Table 8. Parameters]

{#SA-analyzeWithLanguag_S_S__table_jgj_xjl_b2b} {#SA-analyzeWithLanguag_S_S__table_kgj_xjl_b2b__entry__2}

| Type | Description |
|-|-|
| JSON object | Result of the sentiment analysis specifying the status, score, normalized score, sys_id of the relevant connector configuration, and error message. |
[Table 9. Returns]

{#SA-analyzeWithLanguag_S_S__table_kgj_xjl_b2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var result = sa.analyze ("Example string", "en");

Output:

    {"status": "Success", "score": "0.7", "normalizedScore": "0.7", "connectorConfig": "10932aa773101300734e234ffff6a777", errorMessage":""}

## SentimentAnalyser - getConnectorByName(String connectorName) {#ariaid-title8}

Returns the GlideRecord of the specified connector configuration.
{#SA-getConnectorByName_S__table_gx4_cqm_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| connectorName | String | Name of the connector configuration. |
[Table 10. Parameters]

{#SA-getConnectorByName_S__table_gx4_cqm_b2b} {#SA-getConnectorByName_S__table_hx4_cqm_b2b__entry__2}

| Type | Description |
|-|-|
| GlideRecord | GlideRecord of the specified connector configuration. |
[Table 11. Returns]

{#SA-getConnectorByName_S__table_hx4_cqm_b2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var connector = sa.getConnectorByName("xxx");

Output:

    GlideRecord object of the connector configuration with name "xxx", null if no connector is named as "xxx".

## SentimentAnalyser - getDefaultConnector() {#ariaid-title9}

Returns the GlideRecord of the default connector configuration.
{#SA-getDefaultConnector__table_b3c_cpm_b2b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 12. Parameters]

{#SA-getDefaultConnector__table_b3c_cpm_b2b} {#SA-getDefaultConnector__table_c3c_cpm_b2b__entry__2}

| Type | Description |
|-|-|
| GlideRecord | GlideRecord of the default connector configuration. |
[Table 13. Returns]

{#SA-getDefaultConnector__table_c3c_cpm_b2b}  

    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var defaultConnector = sa.getDefaultConnector();


