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

MLPredictor- Global (deprecated)

The MLPredictor API provides utility methods for Predictive Intelligence predictions.

Note: This API has been deprecated and is intended to be removed in a future release. Refer to Using ML APIs for the most recent guidelines.

The MLPredictor API requires the Predictive Intelligence plugin (com.glide.platform_ml) and is provided within the sn_ml namespace.

This class contains all methods necessary to get prediction results from input data.

Parent Topic:Server API reference

MLPredictor - MLPredictor()

Instantiates a new MLPredictor object.

NameTypeDescription
None  

The following example shows how to use an MLPredictor object in a business rule to record final values after a prediction.

function executeRule(current, previous /*null when async*/) {
    var predictor = new MLPredictor();
    predictor.recordFinalValuesInPredictionResults(current, "On close");

}(current, previous);

MLPredictor - applyPrediction(GlideRecord now_GR, Array solutions)

Sets predicted values from an array of specified solutions to a specified record.

NameTypeDescription
now_GRGlideRecordThe record on which to apply the array of predicted solutions.
solutionsArraySpecified solution objects associated with the GlideRecord.
TypeDescription
void 

The following example demonstrates using the applyPrediction() method in a business rule.

(function executeRule(current, previous /*null when async*/) {
    var mlPredictor = new MLPredictor();
    //Get the list of active solutions for the glide record table
    var solutions = mlPredictor.findActiveSolutionsForRecord(current);
    //Run prediction and apply predicted value to the record
    mlPredictor.applyPrediction(current, solution);

})(current, previous);

MLPredictor - applyPredictionForSolution(GlideRecord now_GR, Object solution)

Applies a predicted value from a specified classification solution to the specified GlideRecord.

For each solution in the GlideRecord, call this method to predict the results and set the field value on the incident to those results.

NameTypeDescription
now_GRGlideRecordGlideRecord object containing values on which to run a prediction and apply the results.
solutionObjectClassification solution object to be executed.
TypeDescription
BooleanTrue upon prediction success, error otherwise.

To use this template, copy the Incident Based Prediction (Template) business rule, make the new record Active, and follow the commented instructions to initialize the solutionNames variable.

(function executeRule(current, previous /*null when async*/) {
    var solutionNames = ["solution1", "solution2", ...];

    /* For domain separation (MSP) use case */
//  var solutionNames;
//  if (current.sys_domain == "A")
//      solutionNames = ["solution_A1", "solution_A2", ...];
//  else if (current.sys_domain == "B")
//      solutionNames = ["solution_B1", "solution_B2", ...];
//  else
//      ...

    var predictor = new MLPredictor();
    var info = "";
    solutionNames.forEach(function(solutionName) {
        var solution = predictor.findActiveSolution(solutionName);
        if (!solution)
            return;

        /* The next line of code does the prediction and updates the current record. */
        predictor.applyPredictionForSolution(current, solution);

        /* If no prediction is done, do not build the prediction info message. */
        if (!predictor.applyPredictionForSolution(current, solution))
            return;

        /* If user doesn't have 'itil' role, we don't build prediction info message. */
        if (!gs.hasRole('itil'))
            return;

        /* Building prediction info message */
        var fieldName = solution.getPredictedField();
        var fieldLabel = current.getElement(fieldName).getED().getLabel();
        var predictedDisplayValue = current.getDisplayValue(fieldName);
        var msg = gs.getMessage("Predicted {0} for {1}.", [predictedDisplayValue, fieldLabel]);
        if (info.length > 0)
            info += " ";
        info += msg;
    });
    /* Print out prediction info message on screen. */
    if (info.length > 0) {
        var incidentUrl = "<a href='"+current.getLink()+"'>"+current.number+":</a>";
        gs.addInfoMessage(incidentUrl + " " + info);
    }
})(current, previous);

MLPredictor - findActiveSolution(String solutionName)

Gets the solution object.

This method only returns the solutions if the ml_solution definition and solution are active.

NameTypeDescription
solutionNameStringName of the ml_solution record.
TypeDescription
ObjectSolution object for the specified solutionName if the ml_solution definition and solution is active, null otherwise.

This example takes a hard-coded value and passes it to a specified Machine Learning model. You can use the outcome and confidence variables to set values or other business logic.

var solutionName = 'ml_incident_assignment';
  var shortDescriptionValue = "Unable to connect!"
  var input = {
  short_description : shortDescriptionValue
  };
  var MLP = new MLPredictor();
  var solution = MLP.findActiveSolution(solutionName);
  var predictedOutcome = solution.predictText(input);
  var outcome = predictedOutcome.predictedValue();
  var confidence = predictedOutcome.confidence();
  gs.info("Predicted value: " + outcome)
  gs.info("Confidence: " + confidence)

Output:

DxC_ML:
        ******* Finished Prediction********* *** Script: Predicted value: Software *** Script:
        Confidence: 80.78079080096245

MLPredictor - findActiveSolutionsForRecord(GlideRecord now_GR)

Gets active solutions for a table in a specified GlideRecord.

NameTypeDescription
now_GRGlideRecordGlideRecord from which to collect active solution objects.
TypeDescription
ArrayArray of active solution objects associated with the table that the specified record is for.

This script passes a GlideRecord (such as an incident), and processes all solutions for the GlideRecord, returning the values for each.

/* This is only to get a hard-coded GR */
     var current = new GlideRecord('incident');
     current.get('965c9e5347c12200e0ef563dbb9a7156');
     var predictor = new MLPredictor();
     var solutions = predictor.findActiveSolutionsForRecord(current);
     solutions.forEach(function(solution) {
         var outcome = solution.predict(current);
         /* Use this to set the field to the predicted value in the GlideRecord */
         var fieldName = solution.getPredictedField();
         current[fieldName] = outcome.predictedValue();
         current.update();

         gs.info("Predicted value: " + outcome.predictedValue())
         gs.info("Confidence: " + outcome.confidence())
});

Output (Assignment Group prediction):

DxC_ML: ******* Finished Prediction*********
        *** Script: Predicted value: Software *** Script: Confidence:
        99.74530683715315

Output (Category prediction):

DxC_ML:
        ******* Finished Prediction********* *** Script: Predicted value: Software *** Script:
        Confidence: 98.7172805135524

MLPredictor - getPredictedValue(Object solution, Object outcome)

Gets the predicted value for a specified solution based on the specified prediction outcome.

NameTypeDescription
solutionObjectSolution from which to get the predicted value.
outcomeObjectPrediction outcome results for the specified solution (var outcome = solution.predict(now_GR)).
TypeDescription
StringPredicted value for specified solution based on the specified outcome of the prediction.
NullReturns null if the prediction confidence does not satisfy thresholds.

MLPredictor - getPredictions(GlideRecord now_GR, Object solution, Object options)

Gets predictions for a specified solution.

NameTypeDescription
now\_GRGlideRecordGlideRecord to be predicted.
solutionObjectSolution object to be executed.
optionsObjectOptional JSON object key value pair with the following properties:- options.top\_n: If provided, returns results up to the expected number of predictions, otherwise default is read from the `glide.platform_ml.max_num_predictions` system property. - options.apply\_threshold: Checks the threshold value \(solution threshold for similarity, class level threshold for classification\) for the solution and applies it to the result set. Default value is true.
TypeDescription
ArrayArray of predicted outcome objects

The following example calls a specified solution and executes predictions on it.

function printOutcomeArr(outcomeArr) {
gs.print('################## Results ##################');
for (var i=0; i<outcomeArr.length; i++) {
    var outcome = outcomeArr[i];
    gs.print((i+1) + ' : ' + outcome.predictedValue() + ', ' + outcome.predictedValueSysId() + ', ' + outcome.confidence());
}
}

var solutionName = 'ml_x_snc_global_prop_flip_test';
var predictor = new MLPredictor();
var solution = predictor.findActiveSolution(solutionName);

var now_GR = new GlideRecord('incident');
now_GR.get('1c741bd70b2322007518478d83673af3');

var options = {};
options.top_n = '10';            // top_n is an integer between 1 and 1000
options.apply_threshold = false; // Value can be set to true or false

printOutcomeArr(predictor.getPredictions(now_GR, solution, options));

MLPredictor - isClassificationSolution(Object solution)

Identifies if a solution object is a classification type.

NameTypeDescription
solutionObjectName of the ML solution.
TypeDescription
BooleanReturns true if the input solution is a classification type, false otherwise.
var isClassificationSolution = this.isClassificationSolution(solution);

    //classification solution each class has different threshold
    //therefore needs to get all the results from ml engine
    if (applyThreshold && isClassificationSolution) {
        var maxClassificationTopN = 50;
        outcomeArr = solution.predictTopN(now_GR, maxClassificationTopN);
    }
    else  {
    outcomeArr = solution.predictTopN(now_GR, topN);
    }

    if (outcomeArr === null) {
        //instead of returning null returning empty array
        return [];
    }

MLPredictor - isSimilaritySolution(Object solution)

Identifies if a solution object is a similarity type.

NameTypeDescription
solutionObjectName of the ML solution; for example, ml_incident_categorization.
TypeDescription
BooleanReturns true if the input solution is a similarity type, false otherwise.

MLPredictor - outcome.confidence()

Gets the confidence of the predicted value.

NameTypeDescription
None  
TypeDescription
StringThe estimated precision of the prediction as a percentage. For example, 53.84615375762915.
var MLP = new MLPredictor();
  var solution = MLP.findActiveSolution(solutionName);
  var predictedOutcome = solution.predictText(input);
  var outcome = predictedOutcome.predictedValue();
  var confidence = predictedOutcome.confidence();
  gs.info("Predicted value: " + outcome)
  gs.info("Confidence: " + confidence)

MLPredictor - outcome.predictedValue()

Gets the predicted value from the MLPredictor outcome object.

NameTypeDescription
None  
TypeDescription
StringPredicted value from the Outcome object.
var MLP = new MLPredictor();
  var solution = MLP.findActiveSolution(solutionName);
  var predictedOutcome = solution.predictText(input);
  var outcome = predictedOutcome.predictedValue();
  var confidence = predictedOutcome.confidence();
  gs.info("Predicted value: " + outcome)
  gs.info("Confidence: " + confidence)

MLPredictor - outcome.predictedValueSysId()

Gets the sys_id of the predicted value.

NameTypeDescription
None  
TypeDescription
StringPredicted value sys_id.
function printOutcomeArr(outcomeArr) {
gs.print('################## Results ##################');
for (var i=0; i<outcomeArr.length; i++) {
    var outcome = outcomeArr[i];
    gs.print((i+1) + ' : ' + outcome.predictedValue() + ', ' + outcome.predictedValueSysId() + ', ' + outcome.confidence());
}

MLPredictor - recordFinalValuesInPredictionResults(GlideRecord now_GR, String reason)

Sets final prediction result values to a specified GlideRecord with an optionally specified reason.

NameTypeDescription
now_GRGlideRecordGlideRecord on which to set the final prediction result values.
reasonStringOptional. Reason for applying results.
TypeDescription
void 

In following example, the recordFinalValuesInPredictionResults() method is called when the incident is closed.

(function executeRule(current, previous /*null when async*/) {
    var predictor = new MLPredictor();
    predictor.recordFinalValuesInPredictionResults(current, "On close");

})(current, previous);

MLPredictor - solution.getCapability()

Gets the capability information of a trained solution.

NameTypeDescription
None  
TypeDescription
StringDefinition ID and version of the trained solution, error message otherwise

MLPredictor - solution.getName()

Gets the name of the solution used for prediction.

NameTypeDescription
None  
TypeDescription
StringThe name of the solution to use for predictions; for example, ml_incident_categorization

MLPredictor - solution.getPredictedField()

Gets the predicted value of a solution.

NameTypeDescription
None  
TypeDescription
StringValue of a solution's predicted output field
/* Get a hard-coded GR */
     var current = new GlideRecord('incident');
     current.get('965c9e5347c12200e0ef563dbb9a7156');
     var predictor = new MLPredictor();
     var solutions = predictor.findActiveSolutionsForRecord(current);
     solutions.forEach(function(solution) {
         var outcome = solution.predict(current);
         /* Use this to set the field to the predicted value in the GlideRecord */

         var fieldName = solution.getPredictedField();
         current[fieldName] = outcome.predictedValue();
         current.update();
         gs.info("Predicted value: " + outcome.predictedValue())
         gs.info("Confidence: " + outcome.confidence())
});

MLPredictor - solution.getThreshold(String className)

Gets the solution threshold.

The threshold represents a percentage reflecting the minimum prediction accuracy.

NameTypeDescription
classNameStringA specified categorical value of the solution output field
TypeDescription
NumberValue of the threshold represented as a percentage between 0 and 100.

MLPredictor - solution.getVersion()

Gets the version of the active solution.

NameTypeDescription
None  
TypeDescription
StringVersion of the active solution

MLPredictor - solution.isActive()

Determines if the specified solution is active.

NameTypeDescription
None  
TypeDescription
BooleanTrue if the solution is active, false otherwise

MLPredictor - solution.predict(GlideRecord now_GR, Object threshold)

Gets solution prediction results as an Outcome object.

NameTypeDescription
now_GRGlideRecordGlideRecord of the solution input table
thresholdObjectThreshold value (solution level threshold for similarity, class level threshold for classification)
TypeDescription
ObjectPrediction outcome result of the specified solution (var outcome = solution.predict(now_GR))
solutions.forEach(function(solution) {
         var outcome = solution.predict(current);
         /* Use this to set the field to the predicted value in the GlideRecord
         var fieldName = solution.getPredictedField();
         current[fieldName] = outcome.predictedValue();
         current.update();
         */
         gs.info("Predicted value: " + outcome.predictedValue())
         gs.info("Confidence: " + outcome.confidence())
});

MLPredictor - solution.predictTopN(GlideRecord now_GR, Object topN)

Returns a list of outcome objects up to the expected number of predictions. Maximum number 1000 predictions.

NameTypeDescription
now_GRGlideRecordGlideRecord of the solution
topNObjectExpected number of predictions, any number over 1000 returns 1000 results
TypeDescription
ArrayList of outcome objects in an array including GlideRecord, threshold, system ID, and expected number of predictions (topN object)
var isClassificationSolution = this.isClassificationSolution(solution);

    //classification solution each class has different threshold
    //therefore needs to get all the results from ml engine
    if (applyThreshold && isClassificationSolution) {
        var maxClassificationTopN = 50;
        outcomeArr = solution.predictTopN(now_GR, maxClassificationTopN);
    }
    else  {
        outcomeArr = solution.predictTopN(now_GR, topN);
    }

    if (outcomeArr === null) {
        //instead of returning null returning empty array
        return [];
    }