Skip to content

Background scripts #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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,34 @@


/**
* Deletes records from multiple tables based on provided encoded queries.
*
* @param {Object} target - An object where each key is the name of a table and each value is an encoded query string.
* The function will delete all records matching the encoded query for each specified table.
*
* Example usage:
* bulkDelete({
* 'incident': 'priority=1^state=2',
* 'change_request': 'state=3^risk=high'
* });
*
* This deletes all records in the 'incident' table where the priority is 1 and the state is 2,
* and all records in the 'change_request' table where the state is 3 and risk is 'high'.
*/
function bulkDelete(target) {

for (var table in target) {
if (target.hasOwnProperty(table)) {
var getRecord = new GlideRecord(table);
getRecord.addEncodedQuery(target[table]);
getRecord.query();
while (getRecord.next()) {

getRecord.deleteRecord();
}
}
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Bulk Delete Function Documentation - Use the code/function to bulk-deletes records from multiple tables based on provided encoded queries.

# Function: `bulkDelete(target)`

Deletes records from multiple tables based on provided encoded queries.

## Parameters

- **`target`** (`Object`): An object where each key is the name of a table, and each value is an encoded query string.
- The function will delete all records matching the encoded query for each specified table.

## Example Usage

```javascript
bulkDelete({
'incident': 'priority=1^state=2',
'change_request': 'state=3^risk=high'
});
```

Loading