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' +};