Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'
};