Skip to main content

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:

  1. Read the triggering parent record from input.recordId
  2. Load all child records of the configured type
  3. Update the target field on each child record
  4. 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

KeyDescriptionExample
childTypeChild record type to updateTechnical Scope
fieldToUpdateField to change on each childStatus
newValueNew value to applyRemoved

Inputs

InputRequiredDescription
recordIdYesParent record ID from the workflow trigger

Outputs

OutputDescription
updatedCountNumber of child records updated