Skip to content

Commit 1658b78

Browse files
committed
refactor: Moved ML Model API Integration under RESTMessageV2 folder per guidelines
1 parent 03fa118 commit 1658b78

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Integrate ServiceNow with External ML Model API
2+
3+
## Overview
4+
Call an external ML API from ServiceNow to get AI predictions for incidents and auto-update records.
5+
6+
## What It Does
7+
- Sends incident data to external ML API via REST call
8+
- Receives predictions (resolution time, category, priority, etc.)
9+
- Automatically updates incident record with predictions
10+
- Includes error handling and logging
11+
12+
## Use Cases
13+
- Predict how long an incident will take to resolve
14+
- Auto-suggest the right category/priority
15+
- Recommend best assignment group
16+
- Get risk scores for changes
17+
18+
## Files
19+
- `ml_prediction_script_include.js` - Script Include that calls ML API
20+
21+
## How to Use
22+
1. Create Script Include in ServiceNow named `MLPredictionClient`
23+
2. Copy code from `ml_prediction_script_include.js`
24+
3. Update `ML_API_URL` and `API_KEY` with your ML service details
25+
4. Call it from a Business Rule or Client Script to get predictions
26+
5. Store results back in incident fields
27+
28+
## Example Usage
29+
```javascript
30+
var mlClient = new MLPredictionClient();
31+
var prediction = mlClient.predictIncident({
32+
description: incident.description,
33+
category: incident.category,
34+
priority: incident.priority
35+
});
36+
37+
incident.estimated_resolution_time = prediction.predicted_resolution_time;
38+
incident.update();
39+
```
40+
41+
## Requirements
42+
- ServiceNow instance
43+
- External ML API endpoint (REST)
44+
- API key or token
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Script Include: MLPredictionClient
2+
// Calls external ML API to get incident predictions
3+
4+
var MLPredictionClient = Class.create();
5+
MLPredictionClient.prototype = {
6+
initialize: function() {
7+
this.ML_API_URL = 'https://your-ml-api.com/predict';
8+
this.API_KEY = 'your-api-key-here';
9+
},
10+
11+
predictIncident: function(incidentData) {
12+
try {
13+
var request = new RESTMessageV2();
14+
request.setEndpoint(this.ML_API_URL);
15+
request.setHttpMethod('POST');
16+
request.setRequestHeader('Authorization', 'Bearer ' + this.API_KEY);
17+
request.setRequestHeader('Content-Type', 'application/json');
18+
19+
// Send incident details to ML API
20+
var payload = {
21+
description: incidentData.description,
22+
category: incidentData.category,
23+
priority: incidentData.priority
24+
};
25+
request.setRequestBody(JSON.stringify(payload));
26+
27+
// Get prediction from external ML service
28+
var response = request.execute();
29+
var result = JSON.parse(response.getBody());
30+
31+
return {
32+
estimated_hours: result.estimated_hours,
33+
predicted_category: result.category,
34+
confidence: result.confidence
35+
};
36+
} catch (error) {
37+
gs.log('ML API Error: ' + error, 'MLPredictionClient');
38+
return null;
39+
}
40+
},
41+
42+
type: 'MLPredictionClient'
43+
};

0 commit comments

Comments
 (0)