--- title: MLPredictor - Global \(deprecated\) description: The MLPredictor API provides utility methods for Predictive Intelligence predictions.Instantiates a new MLPredictor object.Sets predicted values from an array of specified solutions to a specified record.Applies a predicted value from a specified classification solution to the specified GlideRecord.Gets the solution object.Gets active solutions for a table in a specified GlideRecord.Gets the predicted value for a specified solution based on the specified prediction outcome.Gets predictions for a specified solution.Identifies if a solution object is a classification type.Identifies if a solution object is a similarity type.Gets the confidence of the predicted value.Gets the predicted value from the MLPredictor outcome object.Gets the sys\_id of the predicted value.Sets final prediction result values to a specified GlideRecord with an optionally specified reason.Gets the capability information of a trained solution.Gets the name of the solution used for prediction.Gets the predicted value of a solution.Gets the solution threshold.Gets the version of the active solution.Determines if the specified solution is active.Gets solution prediction results as an Outcome object.Returns a list of outcome objects up to the expected number of predictions. Maximum number 1000 predictions. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/server-api-reference/c\_MLPredictorAPI.html release: australia product: Server API Reference classification: server-api-reference topic_type: concept last_updated: "2026-03-12" reading_time_minutes: 9 breadcrumb: [Server API reference, API reference, API implementation and reference] --- # 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/intelligent-experiences/using-ml-apis.md) 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md) ## MLPredictor - MLPredictor\(\) Instantiates a new MLPredictor object. |Name|Type|Description| |----|----|-----------| |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. |Name|Type|Description| |----|----|-----------| |now\_GR|GlideRecord|The record on which to apply the array of predicted solutions.| |solutions|Array|Specified solution objects associated with the GlideRecord.| |Type|Description| |----|-----------| |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. |Name|Type|Description| |----|----|-----------| |now\_GR|GlideRecord|GlideRecord object containing values on which to run a prediction and apply the results.| |solution|Object|Classification solution object to be executed.| |Type|Description| |----|-----------| |Boolean|True 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 = ""+current.number+":"; 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. |Name|Type|Description| |----|----|-----------| |solutionName|String|Name of the ml\_solution record.| |Type|Description| |----|-----------| |Object|Solution 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. |Name|Type|Description| |----|----|-----------| |now\_GR|GlideRecord|GlideRecord from which to collect active solution objects.| |Type|Description| |----|-----------| |Array|Array 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. |Name|Type|Description| |----|----|-----------| |solution|Object|Solution from which to get the predicted value.| |outcome|Object|Prediction outcome results for the specified solution \(var outcome = solution.predict\(now\_GR\)\).| |Type|Description| |----|-----------| |String|Predicted value for specified solution based on the specified outcome of the prediction.| |Null|Returns null if the prediction confidence does not satisfy thresholds.| ## MLPredictor - getPredictions\(GlideRecord now\_GR, Object solution, Object options\) Gets predictions for a specified solution.
Name Type Description
now\_GR GlideRecord GlideRecord to be predicted.
solution Object Solution object to be executed.
options Object Optional 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.
|Type|Description| |----|-----------| |Array|Array 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