Field Recommendation based on custom Resource Generator of type "Scripting"

alangross
Tera Expert

Dear forum

 

In a PoC we successfully configured SN Predictive Intelligence to provide Field Recommendations to Incidents (Service, Assignment Group etc.). But now the decision was taken to integrate the customers AI Engine via REST and to not use OOB Predictive Intelligence.

We are now running a new PoC but were so far not able to integrate a scripted resource generator.

On a Recommendation (sn_nb_action_recommended_action) there is the possibility to reference a custom Resource generator (sn_nb_action_resource_generator) of type "Scripting".  There are a few example OOB Resource generators but they seem all to be used for "Similarity (Action Type: Guidance (sn_nb_action_type_definition))" and not for "Categorization (Action Type: Field recommendation (sn_nb_action_type_definition)" .

 

We tried nevertheless to create a script which is based on the OOB Examples but did not succeed so far.

There are no recommendations shown and the log shows the following error:

 

*** Script [ScriptingGeneratorTypeHandler]: Script include 13e4e42187b5ee1c2f880f230cbb355d is invalid: no thrown error


Apparently the Script Include is not returning a value as expected. We were not able to find any documentation about it.

 

The script is for the time being only trying to recommend a single service (hard coded) - just to verify if it is possible to script our own recommendations. The final script would invoke a REST call to retrieve the results.

 

The code is as follows:

var ai_incident_suggestServiceGenerator = Class.create();
ai_incident_suggestServiceGenerator.prototype = Object.extendsObject(sn_nb_action.ScriptingGeneratorHandlerBase, {
    category: 'ra_scripting_generator', // DO NOT REMOVE THIS LINE!

    getId: function() {
        return "sn_sow_inc.ai_incident_suggestServiceGenerator";
    },

    getOutputSchema: function() {
        var schema = [{
            'name': 'predictedRecord',
            'label': 'Predicted Record',
            'type': 'reference',
            'referenceTable': 'cmdb_ci_service'
        }];
        return {
            'status': 'success',
            'schema': schema,
        };
    },

    getOutputs: function(param) {
        try {
            //var nonMLRecommendationsHelper = new sn_sow_inc.NonMLRecommendationsHelper();
            //var similarOpenIncidentsSysIds = nonMLRecommendationsHelper.getSimilarOpenIncidentsWithFilters(param.contextRecord);
            var response = {
                'status': 'success',
                outputs: []
            };
			
			response.outputs.push({predictedRecord: "3ca79da0ad24b0106d379e95d3892905"}); // SV-JIRA

           
            return response;
        } catch (e) {
            return {
                'status': 'error',
                'errorCode': 40001,
                'errorMessage': 'Failed to get Non-ML recommendations for Similar Open Problem records' // this will be logged
            };
        }
    },
    type: 'ai_incident_suggestServiceGenerator'
});

 

Any help is appreciated. 

Thanks and regards

Alan

1 ACCEPTED SOLUTION

alangross
Tera Expert

The Solution was just found in the following community post: 
Re: What is the ScriptingGeneratorFactory? - ServiceNow Community

Kudos to Michael Thomps!

 

The Script Include as shown above works fine. The missing part was a "Extension Point" record that needs to be created for the corresponding Script Include - see sys_extension_instance table (search for point "sn_nb_action.ScriptingGeneratorFactory").

After having created the extension point the resource generator could be mapped as expected:

alangross_0-1750912773545.png

 

 

View solution in original post

1 REPLY 1

alangross
Tera Expert

The Solution was just found in the following community post: 
Re: What is the ScriptingGeneratorFactory? - ServiceNow Community

Kudos to Michael Thomps!

 

The Script Include as shown above works fine. The missing part was a "Extension Point" record that needs to be created for the corresponding Script Include - see sys_extension_instance table (search for point "sn_nb_action.ScriptingGeneratorFactory").

After having created the extension point the resource generator could be mapped as expected:

alangross_0-1750912773545.png