SentimentAnalyser - Scoped

  • Release version: Australia
  • Updated March 12, 2026
  • 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()

    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.

    Table 1. Parameters
    Name Type Description
    configGR GlideRecord GlideRecord object of a connector configuration.
    var sa = new sn_nlp_sentiment.SentimentAnalyser(configGR);

    SentimentAnalyser - analyze(String inputText)

    Performs sentiment analysis on the specified text.

    Table 2. Parameters
    Name Type Description
    inputText String Text on which sentiment analysis should be performed.
    Table 3. Returns
    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.
    
            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.

    Table 4. Parameters
    Name Type Description
    inputTextArray Array Array of text (string) on which to perform sentiment analysis.
    Table 5. Returns
    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.
    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.

    Table 6. Parameters
    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 7. Returns
    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.
    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.

    Table 8. Parameters
    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 9. Returns
    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.
    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.

    Table 10. Parameters
    Name Type Description
    connectorName String Name of the connector configuration.
    Table 11. Returns
    Type Description
    GlideRecord GlideRecord 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.

    Table 12. Parameters
    Name Type Description
    None
    Table 13. Returns
    Type Description
    GlideRecord GlideRecord of the default connector configuration.
    var sa = new sn_nlp_sentiment.SentimentAnalyser();
    var defaultConnector = sa.getDefaultConnector();