What is the ScriptingGeneratorFactory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 10:08 AM
Long story short, I am learning Recommended Actions and trying to build one but I am stuck at the step where you use a generator to use a script.
How do you create a script include for this? It's not a standard script include because an OOB example is
All the documentation says is "You must create an implementation of the scriptinggeneratorfactory template to use a script include on https://docs.servicenow.com/bundle/washingtondc-customer-service-management/page/product/customer-se... and there are no examples. Has anyone set one of these up before know how to create a proper SI for this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 09:27 PM - edited 06-25-2025 10:30 PM
Great!! Thank you so much @Mike-Thompson . It works for me as well. The only missing part was actually the "Extension Point" record.
I have created a corresponding record for my Script Include:
/now/nav/ui/classic/params/target/sys_extension_instance_list.do%3Fsysparm_query%3DpointSTARTSWITHsn_nb_action.ScriptingGeneratorFactory
And after that the resource generator in the Recommendation record could be mapped (sn_nb_action_recommended_action) and everything works:
For Reference my Script Include (which does not do much yet but recommending hardcoded a single service).
var bjbMLOPS_incident_suggestServiceGeneratorV2 = Class.create();
bjbMLOPS_incident_suggestServiceGeneratorV2.prototype = Object.extendsObject(sn_nb_action.ScriptingGeneratorHandlerBase, {
category: 'ra_scripting_generator', // DO NOT REMOVE THIS LINE!
getId: function() {
return "sn_sow_inc.bjbMLOPS_incident_suggestServiceGeneratorV2";
},
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: []
};
// return single service as recommendation (as a test)
response.outputs.push({predictedRecord: "3ca79da0ad24b0106d379e95d3892905"}); // SV-JIRA
return response;
} catch (e) {
return {
'status': 'error',
'errorCode': 40001,
'errorMessage': 'Failed to get recommendations for Incident Service' // this will be logged
};
}
},
type: 'bjbMLOPS_incident_suggestServiceGeneratorV2'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 10:29 PM - edited 06-25-2025 10:30 PM
The hard coded recommendation works - but now I already bump into the next challange.
I try to grab the Incident short_description and description of the Incident. But the parameter object "param" in the function getOutputs contains a contextRecord object with all fields being empty.
Are you able to pass any information to the Scripted Resource generator from the underlying record?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 07:31 AM - edited 06-26-2025 07:45 AM
can you try adding the following lines of code to your script include in the try statement of getOutputs to see if it will give you actual data? I assume that you tried toString or JSON.stringify on param.contextRecord and it looked like "number":{},"short_description":{}.....? I noticed the same but when i dot-walked to the field i got a value.
gs.info("Short Description: " + param.contextRecord.short_description);
gs.info("Description: " + param.contextRecord.description);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 08:12 AM
@Mike-Thompson 🚀 Thank you once more!
Indeed - I was using JSON.stringify - and you are right when using param.contextRecord.short_description it works. Seems to be a special kind of Object.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 12:08 PM
@alangross Glad i was able to help, and i have put together a guide covering all of this which can be found here: https://www.servicenow.com/community/developer-articles/script-your-way-to-smarter-recommended-actio...