Bulk Update Child Records
This script updates all child records of a specific type under the triggered parent record and sets a chosen field to a new value.
Use Case
Use this when you want a workflow trigger to bulk-update child records, for example:
- Mark all Technical Scope items as
Removed - Set all Event Schedule Items to
Cancelled - Change all child records of a given type to a common status
What It Does
On trigger, the script will:
- Read the triggering parent record from
input.recordId - Load all child records of the configured type
- Update the target field on each child record
- Return the total number of updated records
Script
const CONFIG = {
childType: "Your Child Type Name", // Example: "Technical Scope"
fieldToUpdate: "Status", // Example: "Status"
newValue: "Active", // Example: "Removed"
};
if (!input.recordId) {
throw new Error("No parent record ID provided.");
}
const parent = await anydb.getRecordById(input.recordId);
if (!parent) {
throw new Error(`Parent record not found: ${input.recordId}`);
}
const children = await anydb.getChildren(parent.id, {
typename: CONFIG.childType,
});
let updatedCount = 0;
for (const child of children) {
await anydb.yield();
await anydb.updateRecord({
adoid: child.id,
cellValues: {
[CONFIG.fieldToUpdate]: CONFIG.newValue,
},
});
updatedCount += 1;
}
output.set("updatedCount", updatedCount);
log(`Updated ${updatedCount} child records.`);
Configuration
| Key | Description | Example |
|---|---|---|
childType | Child record type to update | Technical Scope |
fieldToUpdate | Field to change on each child | Status |
newValue | New value to apply | Removed |
Inputs
| Input | Required | Description |
|---|---|---|
recordId | Yes | Parent record ID from the workflow trigger |
Outputs
| Output | Description |
|---|---|
updatedCount | Number of child records updated |