Skip to content

Commit 271b1d6

Browse files
authored
Add code snippet to backup Critical Table Data (#1581)
* Add code snippet to backup Critical Table Data * update README description
1 parent ccbd725 commit 271b1d6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Overview
2+
This ServiceNow script automates backing up critical record data (such as task or incident records) to an external storage solution. Designed to run as a Business Rule, it helps maintain redundancy for sensitive information by copying specific record details to a backup API whenever a record is created or modified.
3+
4+
# How It Works
5+
- Data Extraction: Collects key record fields (such as `sys_id`, `number`, `short_description`) from `current`.
6+
- API Call: Sends a `POST` request with record data to an external backup endpoint.
7+
- Logging: Outputs API response for monitoring.
8+
9+
# Implementation
10+
1. Update the `setEndpoint` URL to match your backup API endpoint.
11+
2. Modify the `recordData` with table data structure as needed.
12+
3. Ensure the Business Rule is triggered on the appropriate conditions (e.g., on record insert/update) in the target table.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Script to back up critical table data to external storage
2+
(function executeRule(current, previous /*null when async*/) {
3+
var recordData = {
4+
sys_id: current.sys_id.toString(),
5+
number: current.number.toString(),
6+
short_description: current.short_description.toString()
7+
};
8+
9+
// Call external API to store data
10+
var request = new sn_ws.RESTMessageV2();
11+
request.setEndpoint('https://your-backup-api.com/backup');
12+
request.setHttpMethod('POST');
13+
request.setRequestBody(JSON.stringify(recordData));
14+
15+
var response = request.execute();
16+
gs.info("Backup response: " + response.getBody());
17+
})(current, previous);
18+

0 commit comments

Comments
 (0)