Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

SentimentAnalyser- Scoped

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.

Parent Topic:Server API reference

SentimentAnalyser - SentimentAnalyser()

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)

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

NameTypeDescription
configGRGlideRecordGlideRecord object of a connector configuration.
var sa = new sn_nlp_sentiment.SentimentAnalyser(configGR);

SentimentAnalyser - analyze(String inputText)

Performs sentiment analysis on the specified text.

NameTypeDescription
inputTextStringText on which sentiment analysis should be performed.
TypeDescription
JSON objectResult of the sentiment analysis specifying the status, score, normalised score, sys_id of the relevant connector configuration, and error message.
        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)

Performs sentiment analysis on an array of strings.

NameTypeDescription
inputTextArrayArrayArray of text (string) on which to perform sentiment analysis.
TypeDescription
JSON ArrayAn 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.
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)

Performs sentiment analysis on an array of strings in the specified language.

NameTypeDescription
inputTextArrayArrayArray of text (string) on which to perform sentiment analysis.
languageStringLanguage for the input text. This can very for different sentiment services.
TypeDescription
JSON ArrayAn 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.
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)

Performs sentiment analysis on a specified text and language.

NameTypeDescription
inputTextStringText on which to perform sentiment analysis.
languageStringLanguage for the input text. This can vary for different sentiment services.
TypeDescription
JSON objectResult of the sentiment analysis specifying the status, score, normalized score, sys_id of the relevant connector configuration, and error message.
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)

Returns the GlideRecord of the specified connector configuration.

NameTypeDescription
connectorNameStringName of the connector configuration.
TypeDescription
GlideRecordGlideRecord of the specified connector configuration.
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()

Returns the GlideRecord of the default connector configuration.

NameTypeDescription
None  
TypeDescription
GlideRecordGlideRecord of the default connector configuration.
var sa = new sn_nlp_sentiment.SentimentAnalyser();
var defaultConnector = sa.getDefaultConnector();