From fd37e25421da6ab6524bec85e0e4efb437d3f1d5 Mon Sep 17 00:00:00 2001 From: shriramthebeast Date: Mon, 27 Oct 2025 19:31:24 +0530 Subject: [PATCH 1/5] feat: Add ML Model API Integration snippet - Created Script Include to call external ML prediction APIs - Includes concise documentation with real-world use cases - Shows how to send incident data and receive predictions - Production-ready with error handling and logging --- .../Export Data for ML Training/README.md | 1 - .../Call ML Prediction API/README.md | 44 +++++++++++++++++++ .../ml_prediction_script_include.js | 43 ++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Integration/External ML Model Integration/Call ML Prediction API/README.md create mode 100644 Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js diff --git a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md b/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md index 95896815f8..b12313d7e4 100644 --- a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md +++ b/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md @@ -27,5 +27,4 @@ This snippet shows how to export incident data from ServiceNow and feed it into ## Requirements - ServiceNow instance with REST API access -- Python 3.8+ with requests library - API credentials (username/password or OAuth token) diff --git a/Integration/External ML Model Integration/Call ML Prediction API/README.md b/Integration/External ML Model Integration/Call ML Prediction API/README.md new file mode 100644 index 0000000000..76c63c245d --- /dev/null +++ b/Integration/External ML Model Integration/Call ML Prediction API/README.md @@ -0,0 +1,44 @@ +# Integrate ServiceNow with External ML Model API + +## Overview +Call an external ML API from ServiceNow to get AI predictions for incidents and auto-update records. + +## What It Does +- Sends incident data to external ML API via REST call +- Receives predictions (resolution time, category, priority, etc.) +- Automatically updates incident record with predictions +- Includes error handling and logging + +## Use Cases +- Predict how long an incident will take to resolve +- Auto-suggest the right category/priority +- Recommend best assignment group +- Get risk scores for changes + +## Files +- `ml_prediction_script_include.js` - Script Include that calls ML API + +## How to Use +1. Create Script Include in ServiceNow named `MLPredictionClient` +2. Copy code from `ml_prediction_script_include.js` +3. Update `ML_API_URL` and `API_KEY` with your ML service details +4. Call it from a Business Rule or Client Script to get predictions +5. Store results back in incident fields + +## Example Usage +```javascript +var mlClient = new MLPredictionClient(); +var prediction = mlClient.predictIncident({ + description: incident.description, + category: incident.category, + priority: incident.priority +}); + +incident.estimated_resolution_time = prediction.predicted_resolution_time; +incident.update(); +``` + +## Requirements +- ServiceNow instance +- External ML API endpoint (REST) +- API key or token diff --git a/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js b/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js new file mode 100644 index 0000000000..1adf1a9c0e --- /dev/null +++ b/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js @@ -0,0 +1,43 @@ +// Script Include: MLPredictionClient +// Calls external ML API to get incident predictions + +var MLPredictionClient = Class.create(); +MLPredictionClient.prototype = { + initialize: function() { + this.ML_API_URL = 'https://your-ml-api.com/predict'; + this.API_KEY = 'your-api-key-here'; + }, + + predictIncident: function(incidentData) { + try { + var request = new RESTMessageV2(); + request.setEndpoint(this.ML_API_URL); + request.setHttpMethod('POST'); + request.setRequestHeader('Authorization', 'Bearer ' + this.API_KEY); + request.setRequestHeader('Content-Type', 'application/json'); + + // Send incident details to ML API + var payload = { + description: incidentData.description, + category: incidentData.category, + priority: incidentData.priority + }; + request.setRequestBody(JSON.stringify(payload)); + + // Get prediction from external ML service + var response = request.execute(); + var result = JSON.parse(response.getBody()); + + return { + estimated_hours: result.estimated_hours, + predicted_category: result.category, + confidence: result.confidence + }; + } catch (error) { + gs.log('ML API Error: ' + error, 'MLPredictionClient'); + return null; + } + }, + + type: 'MLPredictionClient' +}; From b4447801080b8ce7dec743b087ffa66581bed3a5 Mon Sep 17 00:00:00 2001 From: Sriram kulkarni <165943146+BEASTSHRIRAM@users.noreply.github.com> Date: Mon, 27 Oct 2025 22:12:45 +0530 Subject: [PATCH 2/5] Delete Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md --- .../Export Data for ML Training/README.md | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md diff --git a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md b/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md deleted file mode 100644 index b12313d7e4..0000000000 --- a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Export ServiceNow Data to ML Pipeline - -## Overview -This snippet shows how to export incident data from ServiceNow and feed it into an external ML pipeline for analysis and predictions. - -## What It Does -- **Script Include**: Queries incidents from ServiceNow -- **Scripted REST API**: Exposes data as JSON endpoint -- **Python Script**: Consumes data, preprocesses it, and runs basic ML operations -- **Result Storage**: Sends predictions back to ServiceNow - -## Use Cases -- Predict incident resolution time -- Classify tickets automatically -- Detect anomalies in service data -- Smart assignment recommendations - -## Files -- `data_export_script_include.js` - Server-side Script Include to query incident data -- `export_data_rest_api.js` - Scripted REST API to expose data as JSON endpoint - -## How to Use -1. Create a Script Include in ServiceNow named `MLDataExporter` using `data_export_script_include.js` -2. Create a Scripted REST API with base path `/api/ml_export` and resource `/incidents` using `export_data_rest_api.js` -3. Call the endpoint: `GET /api/ml_export/incidents?limit=100` -4. External ML systems can fetch formatted incident data via this REST endpoint - -## Requirements -- ServiceNow instance with REST API access -- API credentials (username/password or OAuth token) From 776a64625278e15fbb62ad53242d174e56b4a00d Mon Sep 17 00:00:00 2001 From: shriramthebeast Date: Mon, 27 Oct 2025 22:18:59 +0530 Subject: [PATCH 3/5] fix: Restore accidentally deleted README for ML Data Export snippet --- .../Export Data for ML Training/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md b/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md index b12313d7e4..95896815f8 100644 --- a/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md +++ b/Integration/Data Export to ML Pipeline/Export Data for ML Training/README.md @@ -27,4 +27,5 @@ This snippet shows how to export incident data from ServiceNow and feed it into ## Requirements - ServiceNow instance with REST API access +- Python 3.8+ with requests library - API credentials (username/password or OAuth token) From 1658b78bbf799681caeb6db80628d54f449cf2f8 Mon Sep 17 00:00:00 2001 From: shriramthebeast Date: Tue, 28 Oct 2025 13:31:22 +0530 Subject: [PATCH 4/5] refactor: Moved ML Model API Integration under RESTMessageV2 folder per guidelines --- .../Call ML Prediction API/README.md | 44 +++++++++++++++++++ .../ml_prediction_script_include.js | 43 ++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/README.md create mode 100644 Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js diff --git a/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/README.md b/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/README.md new file mode 100644 index 0000000000..76c63c245d --- /dev/null +++ b/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/README.md @@ -0,0 +1,44 @@ +# Integrate ServiceNow with External ML Model API + +## Overview +Call an external ML API from ServiceNow to get AI predictions for incidents and auto-update records. + +## What It Does +- Sends incident data to external ML API via REST call +- Receives predictions (resolution time, category, priority, etc.) +- Automatically updates incident record with predictions +- Includes error handling and logging + +## Use Cases +- Predict how long an incident will take to resolve +- Auto-suggest the right category/priority +- Recommend best assignment group +- Get risk scores for changes + +## Files +- `ml_prediction_script_include.js` - Script Include that calls ML API + +## How to Use +1. Create Script Include in ServiceNow named `MLPredictionClient` +2. Copy code from `ml_prediction_script_include.js` +3. Update `ML_API_URL` and `API_KEY` with your ML service details +4. Call it from a Business Rule or Client Script to get predictions +5. Store results back in incident fields + +## Example Usage +```javascript +var mlClient = new MLPredictionClient(); +var prediction = mlClient.predictIncident({ + description: incident.description, + category: incident.category, + priority: incident.priority +}); + +incident.estimated_resolution_time = prediction.predicted_resolution_time; +incident.update(); +``` + +## Requirements +- ServiceNow instance +- External ML API endpoint (REST) +- API key or token diff --git a/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js b/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js new file mode 100644 index 0000000000..1adf1a9c0e --- /dev/null +++ b/Integration/RESTMessageV2/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js @@ -0,0 +1,43 @@ +// Script Include: MLPredictionClient +// Calls external ML API to get incident predictions + +var MLPredictionClient = Class.create(); +MLPredictionClient.prototype = { + initialize: function() { + this.ML_API_URL = 'https://your-ml-api.com/predict'; + this.API_KEY = 'your-api-key-here'; + }, + + predictIncident: function(incidentData) { + try { + var request = new RESTMessageV2(); + request.setEndpoint(this.ML_API_URL); + request.setHttpMethod('POST'); + request.setRequestHeader('Authorization', 'Bearer ' + this.API_KEY); + request.setRequestHeader('Content-Type', 'application/json'); + + // Send incident details to ML API + var payload = { + description: incidentData.description, + category: incidentData.category, + priority: incidentData.priority + }; + request.setRequestBody(JSON.stringify(payload)); + + // Get prediction from external ML service + var response = request.execute(); + var result = JSON.parse(response.getBody()); + + return { + estimated_hours: result.estimated_hours, + predicted_category: result.category, + confidence: result.confidence + }; + } catch (error) { + gs.log('ML API Error: ' + error, 'MLPredictionClient'); + return null; + } + }, + + type: 'MLPredictionClient' +}; From 03b02b2e06a0f53782b40bfd583bdbf9dd9ff02d Mon Sep 17 00:00:00 2001 From: shriramthebeast Date: Tue, 28 Oct 2025 13:33:30 +0530 Subject: [PATCH 5/5] changes done --- .../Call ML Prediction API/README.md | 44 ------------------- .../ml_prediction_script_include.js | 43 ------------------ 2 files changed, 87 deletions(-) delete mode 100644 Integration/External ML Model Integration/Call ML Prediction API/README.md delete mode 100644 Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js diff --git a/Integration/External ML Model Integration/Call ML Prediction API/README.md b/Integration/External ML Model Integration/Call ML Prediction API/README.md deleted file mode 100644 index 76c63c245d..0000000000 --- a/Integration/External ML Model Integration/Call ML Prediction API/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Integrate ServiceNow with External ML Model API - -## Overview -Call an external ML API from ServiceNow to get AI predictions for incidents and auto-update records. - -## What It Does -- Sends incident data to external ML API via REST call -- Receives predictions (resolution time, category, priority, etc.) -- Automatically updates incident record with predictions -- Includes error handling and logging - -## Use Cases -- Predict how long an incident will take to resolve -- Auto-suggest the right category/priority -- Recommend best assignment group -- Get risk scores for changes - -## Files -- `ml_prediction_script_include.js` - Script Include that calls ML API - -## How to Use -1. Create Script Include in ServiceNow named `MLPredictionClient` -2. Copy code from `ml_prediction_script_include.js` -3. Update `ML_API_URL` and `API_KEY` with your ML service details -4. Call it from a Business Rule or Client Script to get predictions -5. Store results back in incident fields - -## Example Usage -```javascript -var mlClient = new MLPredictionClient(); -var prediction = mlClient.predictIncident({ - description: incident.description, - category: incident.category, - priority: incident.priority -}); - -incident.estimated_resolution_time = prediction.predicted_resolution_time; -incident.update(); -``` - -## Requirements -- ServiceNow instance -- External ML API endpoint (REST) -- API key or token diff --git a/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js b/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js deleted file mode 100644 index 1adf1a9c0e..0000000000 --- a/Integration/External ML Model Integration/Call ML Prediction API/ml_prediction_script_include.js +++ /dev/null @@ -1,43 +0,0 @@ -// Script Include: MLPredictionClient -// Calls external ML API to get incident predictions - -var MLPredictionClient = Class.create(); -MLPredictionClient.prototype = { - initialize: function() { - this.ML_API_URL = 'https://your-ml-api.com/predict'; - this.API_KEY = 'your-api-key-here'; - }, - - predictIncident: function(incidentData) { - try { - var request = new RESTMessageV2(); - request.setEndpoint(this.ML_API_URL); - request.setHttpMethod('POST'); - request.setRequestHeader('Authorization', 'Bearer ' + this.API_KEY); - request.setRequestHeader('Content-Type', 'application/json'); - - // Send incident details to ML API - var payload = { - description: incidentData.description, - category: incidentData.category, - priority: incidentData.priority - }; - request.setRequestBody(JSON.stringify(payload)); - - // Get prediction from external ML service - var response = request.execute(); - var result = JSON.parse(response.getBody()); - - return { - estimated_hours: result.estimated_hours, - predicted_category: result.category, - confidence: result.confidence - }; - } catch (error) { - gs.log('ML API Error: ' + error, 'MLPredictionClient'); - return null; - } - }, - - type: 'MLPredictionClient' -};