Skip to content

Commit 543b15b

Browse files
templetontsaiTempleton Tsaikmxo
authored
Background scripts (#1091)
* Bulk Update Function - Use the code/function to bulk change some fields in any tables in your background script and in any other serverside scripts. * Bulk Delete Function - Use the code/function to bulk-deletes records from multiple tables based on provided encoded queries. * Delete Background Scripts/Bulk Update Tables/Readme.md File already sent * Delete Background Scripts/Bulk Update Tables/BulkUpdateWithConditions.js File already sent --------- Co-authored-by: Templeton Tsai <[email protected]> Co-authored-by: Carlos Camacho Junior <[email protected]>
1 parent aacbf5f commit 543b15b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
3+
/**
4+
* Deletes records from multiple tables based on provided encoded queries.
5+
*
6+
* @param {Object} target - An object where each key is the name of a table and each value is an encoded query string.
7+
* The function will delete all records matching the encoded query for each specified table.
8+
*
9+
* Example usage:
10+
* bulkDelete({
11+
* 'incident': 'priority=1^state=2',
12+
* 'change_request': 'state=3^risk=high'
13+
* });
14+
*
15+
* This deletes all records in the 'incident' table where the priority is 1 and the state is 2,
16+
* and all records in the 'change_request' table where the state is 3 and risk is 'high'.
17+
*/
18+
function bulkDelete(target) {
19+
20+
for (var table in target) {
21+
if (target.hasOwnProperty(table)) {
22+
var getRecord = new GlideRecord(table);
23+
getRecord.addEncodedQuery(target[table]);
24+
getRecord.query();
25+
while (getRecord.next()) {
26+
27+
getRecord.deleteRecord();
28+
}
29+
}
30+
}
31+
}
32+
33+
34+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Bulk Delete Function Documentation - Use the code/function to bulk-deletes records from multiple tables based on provided encoded queries.
2+
3+
# Function: `bulkDelete(target)`
4+
5+
Deletes records from multiple tables based on provided encoded queries.
6+
7+
## Parameters
8+
9+
- **`target`** (`Object`): An object where each key is the name of a table, and each value is an encoded query string.
10+
- The function will delete all records matching the encoded query for each specified table.
11+
12+
## Example Usage
13+
14+
```javascript
15+
bulkDelete({
16+
'incident': 'priority=1^state=2',
17+
'change_request': 'state=3^risk=high'
18+
});
19+
```
20+

0 commit comments

Comments
 (0)