MLPredictor - Global (deprecated)

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 28분
  • The MLPredictor API provides utility methods for Predictive Intelligence predictions.

    주:
    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.

    MLPredictor - MLPredictor()

    Instantiates a new MLPredictor object.

    표 1. Parameters
    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.

    표 2. Parameters
    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.
    표 3. Returns
    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.

    표 4. Parameters
    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.
    표 5. Returns
    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 = "<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.

    표 6. Parameters
    Name Type Description
    solutionName String Name of the ml_solution record.
    표 7. Returns
    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.

    표 8. Parameters
    Name Type Description
    now_GR GlideRecord GlideRecord from which to collect active solution objects.
    표 9. Returns
    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.

    표 10. Parameters
    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)).
    표 11. Returns
    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.

    표 12. Parameters
    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.
    표 13. Returns
    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<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.

    표 14. Parameters
    Name Type Description
    solution Object Name of the ML solution.
    표 15. Returns
    Type Description
    Boolean Returns 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.

    표 16. Parameters
    Name Type Description
    solution Object Name of the ML solution; for example, ml_incident_categorization.
    표 17. Returns
    Type Description
    Boolean Returns true if the input solution is a similarity type, false otherwise.

    MLPredictor - outcome.confidence()

    Gets the confidence of the predicted value.

    표 18. Parameters
    Name Type Description
    None
    표 19. Returns
    Type Description
    String The 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.

    표 20. Parameters
    Name Type Description
    None
    표 21. Returns
    Type Description
    String Predicted 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.

    표 22. Parameters
    Name Type Description
    None
    표 23. Returns
    Type Description
    String Predicted 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.

    표 24. Parameters
    Name Type Description
    now_GR GlideRecord GlideRecord on which to set the final prediction result values.
    reason String Optional. Reason for applying results.
    표 25. Returns
    Type Description
    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.

    표 26. Parameters
    Name Type Description
    None
    표 27. Returns
    Type Description
    String Definition ID and version of the trained solution, error message otherwise

    MLPredictor - solution.getName()

    Gets the name of the solution used for prediction.

    표 28. Parameters
    Name Type Description
    None
    표 29. Returns
    Type Description
    String The name of the solution to use for predictions; for example, ml_incident_categorization

    MLPredictor - solution.getPredictedField()

    Gets the predicted value of a solution.

    표 30. Parameters
    Name Type Description
    None
    표 31. Returns
    Type Description
    String Value 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.

    표 32. Parameters
    Name Type Description
    className String A specified categorical value of the solution output field
    표 33. Returns
    Type Description
    Number Value of the threshold represented as a percentage between 0 and 100.

    MLPredictor - solution.getVersion()

    Gets the version of the active solution.

    표 34. Parameters
    Name Type Description
    None
    표 35. Returns
    Type Description
    String Version of the active solution

    MLPredictor - solution.isActive()

    Determines if the specified solution is active.

    표 36. Parameters
    Name Type Description
    None
    표 37. Returns
    Type Description
    Boolean True if the solution is active, false otherwise

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

    Gets solution prediction results as an Outcome object.

    표 38. Parameters
    Name Type Description
    now_GR GlideRecord GlideRecord of the solution input table
    threshold Object Threshold value (solution level threshold for similarity, class level threshold for classification)
    표 39. Returns
    Type Description
    Object Prediction 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.

    표 40. Parameters
    Name Type Description
    now_GR GlideRecord GlideRecord of the solution
    topN Object Expected number of predictions, any number over 1000 returns 1000 results
    표 41. Returns
    Type Description
    Array List 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 [];
    	}