---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# MLSolution - Global

# MLSolution - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes to read

The MLSolution API provides methods for handling Predictive Intelligence predictions and retrieving solution objects for all capabilities: similarity, classification, and clustering).  
This API provides methods commonly used among all solution capabilities and methods unique to classification and clustering solutions.

* Common methods used for all solution objects:
  * getCapability()
  * getVersion()
  * isActive()
  * predict()
  {#MLSolutionAPI__ul_uyg_bjy_xjb}
* Methods only used for classification and regression solutions:
  * applyPrediction()
  {#MLSolutionAPI__ul_wls_bjy_xjb}
* Methods only used for clustering solutions:
  * getClusterAssignments()
  * getClusterForRecord()
  * getClusterInfo()
  {#MLSolutionAPI__ul_j35_bjy_xjb}
{#MLSolutionAPI__ul_cd1_1jy_xjb}

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

The methods in this object are instantiated using [MLSolutionFactory](https://servicenow-prod.fluidtopics.net/xyZUi2WTJ_1ypDwYtT86jg#MLSolutionFactoryAPI "The MLSolutionFactory API is a factory class to get an MLSolution scriptable object.").{#MLSolutionAPI__classInstantMLSF}
**Related concepts**   

* [MLSolutionUtil](https://servicenow-prod.fluidtopics.net/1cQ4_TaoEGg8FOCirG46RQ#MLSolutionUtilAPI "The MLSolutionUtil script include provides methods for getting Predictive Intelligence predictions.")
* [REST API: Get predictions for multiple solutions](https://servicenow-prod.fluidtopics.net/4_wEe9KV95LgGzRpMcfszA#agent-intelligence-api "The Predictive Intelligence API provides endpoints that predict a field value based on one or more input fields and a trained solution.")

## MLSolution - applyPrediction(GlideRecord now_GR) {#ariaid-title2}

Gets the prediction result for a classification solution and applies it to the input
GlideRecord if the confidence value is higher than the threshold.
{#MLSolution-applyPrediction_GR__table_hqw_pbm_yfb__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | GlideRecord object containing values on which to run a prediction and apply the results. |
[Table 1. Parameters]

{#MLSolution-applyPrediction_GR__table_hqw_pbm_yfb} {#MLSolution-applyPrediction_GR__table_iqw_pbm_yfb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the prediction was applied: * true: Prediction applied * false: Prediction rejected {#MLSolution-applyPrediction_GR__ul_pvl_ggm_ckb} |
[Table 2. Returns]

{#MLSolution-applyPrediction_GR__table_iqw_pbm_yfb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_incident_categorization");

    var inputGR = new GlideRecord("incident");
    inputGR.get("0ef47232db801300864adfea5e961912");

    mlSolution.applyPrediction(inputGR);

## MLSolution - getCapability() {#ariaid-title3}

Gets the capability information of a trained solution.
{#MLSolution-getCapability__table_em3_pfx_ggb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#MLSolution-getCapability__table_em3_pfx_ggb} {#MLSolution-getCapability__table_fm3_pfx_ggb__entry__2}

| Type | Description |
|-|-|
| String | Type of trained solution. Possible values: * Similarity * Classification * Clustering {#MLSolution-getCapability__ul_sv5_slm_ckb} |
[Table 4. Returns]

{#MLSolution-getCapability__table_fm3_pfx_ggb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_x_global_clustering");

    // configure optional parameters
    var options = {};
    options.group_by = 'network';
    options.cluster_id = 1;
    options.top_n_per_cluster = 3;

    if (mlSolution.getCapability() == 'clustering') {
    	var results = mlSolution.getClusterAssignments(options);
    	// pretty print JSON results
    	gs.print(JSON.stringify(JSON.parse(results), null, 2));
    }

## MLSolution - getClusterAssignments(Object options) {#ariaid-title4}

Gets assignments for a clustering solution.
{#MLSolution-getClusterAssignments_O__table_t1q_hxt_rhb__entry__3}{#MLSolution-getClusterAssignments_O__ml-cluster-create-xbl}

| Name | Type | Description |
|-|-|-|
| options | Object | Optional. Values to use to narrow down the returned results by group and level within a clustering solution. Default: Return cluster memberships for all clusters. |
| options.group_by | String | Optional. Identifies the segmentation field for which to retrieve cluster memberships, for example, assignment_group. This field provides the same grouping as options provided in the Use Group By check box in the Clustering Definition form. The information provided varies based on the table selected in the Table field. For more information, see [Create and train a clustering solution](https://www.servicenow.com/docs/access?context=create-clustering-solution&version=xanadu&pubname=xanadu-intelligent-experiences&ft:locale=en-US) . |
| options.cluster_id | String | Optional. Cluster ID of a trained solution in the Cluster Summary \[ml_cluster_summary\] table. |
| options.top_n_per_cluster | Number | Number of top results to receive for each cluster. |
[Table 5. Parameters]

{#MLSolution-getClusterAssignments_O__table_t1q_hxt_rhb} {#MLSolution-getClusterAssignments_O__table_u1q_hxt_rhb__entry__2}

| Type | Description |
|-|-|
| Object | JSON array containing cluster information in increasing order by cluster_id: * cluster_id: String. Unique cluster number within a solution of clusters.{#MLSolution-getClusterAssignments_O__mlv-getClusterInfo-returnsID} * rec_display_id: String. Record type and number.{#MLSolution-getClusterAssignments_O__mlv-GetClustrAssn-rec-dispid} * rec_sys_id: String. Record sys_id.{#MLSolution-getClusterAssignments_O__mlv-GetClustrAssn-rec-sysid} * group_by: If grouped, name of the segmentation field associated with this cluster.{#MLSolution-getClusterAssignments_O__mlv-getClusterInfo-returnsGrp} {#MLSolution-getClusterAssignments_O__ul_oz5_dwm_rhb} |
[Table 6. Returns]

{#MLSolution-getClusterAssignments_O__table_u1q_hxt_rhb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_x_global_clustering");

    // configure optional parameters
    var options = {};
    options.group_by = 'network';
    options.cluster_id = '1';
    // returns top 3 results per cluster
    options.top_n_per_cluster = 3;

    var results = mlSolution.getClusterAssignments(options);

Output:

    [{"cluster_id":"1","rec_display_id":"Incident: INC0014483","rec_sys_id":"04e33e7adb401300864adfea5e961900","group_by":"network"},
     {"cluster_id":"1","rec_display_id":"Incident: INC0011133","rec_sys_id":"5bd23af2db401300864adfea5e96194d","group_by":"network"}]

## MLSolution - getClusterForRecord(GlideRecord now_GR) {#ariaid-title5}

Gets the cluster information for a clustering solution.
{#MLSolution-getClusterForRecord_GR__table_ak2_xcn_rhb__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | Name of the input GlideRecord. |
[Table 7. Parameters]

{#MLSolution-getClusterForRecord_GR__table_ak2_xcn_rhb} {#MLSolution-getClusterForRecord_GR__table_bk2_xcn_rhb__entry__2}

| Type | Description |
|-|-|
| String | The cluster_id from the Cluster Summary \[ml_cluster_summary\] table if the record belongs to a cluster. Empty string returns if the record does not belong to a cluster. |
[Table 8. Returns]

{#MLSolution-getClusterForRecord_GR__table_bk2_xcn_rhb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("solution_name");
    var now_GR = new GlideRecord('incident');
    if (mlSolution.getCapability() == 'clustering') {
    var clusterId = mlSolution.getClusterForRecord(now_GR);
    }

## MLSolution - getClusterInfo(Object options) {#ariaid-title6}

Gets information for a specified clustering solution.
{#MLSolution-getClusterInfo_O__table_ak2_xcn_rhb__entry__3}{#MLSolution-getClusterInfo_O__ml-cluster-create-xbl}

| Name | Type | Description |
|-|-|-|
| options | Object | Optional. Narrows down the returned results by group and level within a clustering solution. Default: Return cluster memberships for all clusters. |
| options.group_by | String | Optional. Identifies the segmentation field for which to retrieve cluster memberships, for example, assignment_group. This field provides the same grouping as options provided in the Use Group By check box in the Clustering Definition form. The information provided varies based on the table selected in the Table field. For more information, see [Create and train a clustering solution](https://www.servicenow.com/docs/access?context=create-clustering-solution&version=xanadu&pubname=xanadu-intelligent-experiences&ft:locale=en-US) . |
| options.cluster_id | String | Optional. Cluster ID of a trained solution in the Cluster Summary \[ml_cluster_summary\] table. |
[Table 9. Parameters]

{#MLSolution-getClusterInfo_O__table_ak2_xcn_rhb} {#MLSolution-getClusterInfo_O__table_bk2_xcn_rhb__entry__2}

| Type | Description |
|-|-|
| Object | JSON array containing cluster information in increasing order by cluster_id: * cluster_id: String. Unique cluster number within a solution of clusters.{#MLSolution-getClusterInfo_O__mlv-getClusterInfo-returnsID} * cluster_quality: String. Number from 0 to 100. Higher numbers indicate higher cluster density.{#MLSolution-getClusterInfo_O__mlv-getClusterInfo-returnsCQ} * cluster_size: String. Number of records in a cluster.{#MLSolution-getClusterInfo_O__mlv-getClusterInfo-returnsSize} * group_by: If grouped, name of the segmentation field associated with this cluster.{#MLSolution-getClusterInfo_O__mlv-getClusterInfo-returnsGrp} * cluster_concept: String. Set of words that describe the cluster in descending order of frequency.{#MLSolution-getClusterInfo_O__mlv-getClusterInfo-returnsConcept} {#MLSolution-getClusterInfo_O__ul_oz5_tv5_rhb} |
[Table 10. Returns]

{#MLSolution-getClusterInfo_O__table_bk2_xcn_rhb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_x_global_clustering");

    // configure optional parameters
    var options = {};
    options.group_by = 'network';
    options.cluster_id = 1;

    var results = mlSolution.getClusterInfo(options);

Output:

    [ {"cluster_id":"1","cluster_quality":"56.6","cluster_size":"46","group_by":"SLA","cluster_concept":"issue occur capacity ..."},
      {"cluster_id":"2","cluster_quality":"55.47","cluster_size":"75","group_by":"SLA","cluster_concept":"clone instance request ..."},
    ... ]

## MLSolution - getVersion() {#ariaid-title7}

Gets the version of the active solution.
{#MLSolution-getVersion__table_hrt_ngx_ggb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#MLSolution-getVersion__table_hrt_ngx_ggb} {#MLSolution-getVersion__table_irt_ngx_ggb__entry__2}

| Type | Description |
|-|-|
| String | Version of the active solution. |
[Table 12. Returns]

{#MLSolution-getVersion__table_irt_ngx_ggb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("solution_name");

    var solutionVersion = mlSolution.getVersion();

## MLSolution - isActive() {#ariaid-title8}

Determines if a solution is active.
{#MLSolution-isActive__table_xzj_lgx_ggb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#MLSolution-isActive__table_xzj_lgx_ggb} {#MLSolution-isActive__table_yzj_lgx_ggb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the solution is active. * true: Solution active * false: Solution inactive {#MLSolution-isActive__ul_cnk_ltv_bkb} |
[Table 14. Returns]

{#MLSolution-isActive__table_yzj_lgx_ggb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("solution_name");

    var isActive = mlSolution.isActive();

## MLSolution - predict(Object input, Object options) {#ariaid-title9}

Gets the prediction results from the prediction server given a GlideRecord or an array
of key-value pairs.
You can use this method to call prediction with multiple input records because GlideRecord
is an iterator.
{#MLSolution-predict_O_O__table_vv5_yfx_ggb__entry__3}

| Name | Type | Description |
|-|-|-|
| input | Object | [GlideRecord](https://servicenow-prod.fluidtopics.net/nRmUiaC7a08cr2N5iZGqoQ#c_GlideRecordAPI "The GlideRecord API is used for database operations.") or array of JSON objects containing field names and values as key-value pairs. |
| options | Object | Optional. JSON key-value pair with the following properties: * top_n: Number. If provided, returns the top results, up to the specified number of predictions.{#MLSolution-predict_O_O__solution-prediction-topn} * apply_threshold: Boolean. Checks the threshold value for the solution and applies it to the result set. The threshold value is solution threshold for similarity or class-level threshold for classification. Default value is true.{#MLSolution-predict_O_O__solution-prediction-thresh} * custom_results_filter: String. Similarity solutions only. Specifies the allowed set from which results are returned using an encoded query.{#MLSolution-predict_O_O__solution-prediction-custom} {#MLSolution-predict_O_O__ul_eqd_tcs_ckb} |
[Table 15. Parameters]

{#MLSolution-predict_O_O__table_vv5_yfx_ggb} {#MLSolution-predict_O_O__table_khq_hgx_ggb__entry__2}

| Type | Description |
|-|-|
| Object | JSON object containing the prediction results sorted by sys_id or record_number. * predictedValue: String. Value representing the prediction result.{#MLSolution-predict_O_O__ml-returnsVal} * predictedSysId: String. The sys_id of the predicted value. Results can be from any table on which information is being predicted.{#MLSolution-predict_O_O__ml-returnsID} * confidence: Number. Value of the confidence associated with the prediction. For example, 53.84.{#MLSolution-predict_O_O__ml-returnsConf} * threshold: Number. Value of the configured threshold associated with the prediction.{#MLSolution-predict_O_O__ml-returnsThrsh} {#MLSolution-predict_O_O__ul_fg2_vcs_ckb} |
[Table 16. Returns]

{#MLSolution-predict_O_O__table_khq_hgx_ggb}  

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_incident_categorization");

    // single GlideRecord input
    var input = new GlideRecord("incident");
    input.get("0ef47232db801300864adfea5e961912");

    // configure optional parameters
    var options = {};
    options.top_n = 3;
    options.apply_threshold = false;

    var results = mlSolution.predict(input, options);
    // pretty print JSON results
    gs.print(JSON.stringify(JSON.parse(results), null, 2));

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_incident_categorization");

    // multiple GlideRecord input
    var input = new GlideRecord("incident");
    input.addQuery("sys_created_onONLast week@javascript:gs.beginningOfLastWeek()@javascript:gs.endOfLastWeek()");
    input.query();

    // configure optional parameters
    var options = {};
    options.top_n = 3;
    options.apply_threshold = false;

    var results = mlSolution.predict(input, options);
    // pretty print JSON results
    gs.print(JSON.stringify(JSON.parse(results), null, 2));

Output:

    {
        input_gr_sys_id1: [
                    {
                        predictedValue : xxx,
                        predictedSysId : xx0,
                        confidence : xxx,
                        threshold : xxx

                    }, 
                    {
                        predictedValue : yyy,
                        predictedSysId : xx1,
                        confidence : xxx,
                        threshold : xxx
                    }
            ],
        input_gr_sys_id2 : [
                    {
                        predictedValue : xxx,
                        predictedSysId : xx0,
                        confidence : xxx,
                        threshold : xxx

                    }, 
                ...
            ]
    }

    var mlSolution = sn_ml.MLSolutionFactory.getSolution("ml_incident_categorization");

    // key-value pairs input
    var input = [{"short_description":"my email is not working"}, 
    			{short_description:"need help with password"}];

    // configure optional parameters
    var options = {};
    options.top_n = 3;
    options.apply_threshold = false;

    var results = mlSolution.predict(input, options);
    // pretty print JSON results
    gs.print(JSON.stringify(JSON.parse(results), null, 2));


