@DimuDesigns’ warning about the retention windows is the most important thing here — act fast. To give you the actual snippets you asked for:
**Enable the advanced services first** (Apps Script editor → Services +): add **Drive Activity API** and **Drive API** (v3). The Activity service appears as `DriveActivity` and Drive as `Drive`.
**1. Query activity to find a file’s previous parent(s):**
```javascript
function findOriginalParents(fileId) {
const request = {
itemName: 'items/' + fileId, // scope to one file
filter: 'time >= "2026-03-15T00:00:00Z" AND detail.action_detail_case:MOVE',
pageSize: 100
};
let parents = [];
let pageToken;
do {
if (pageToken) request.pageToken = pageToken;
const resp = DriveActivity.Activity.query(request);
(resp.activities || \[\]).forEach(act => {
(act.actions || \[\]).forEach(a => {
if (a.detail && a.detail.move) {
// removedParents holds where it was moved OUT of = the prior location
(a.detail.move.removedParents || \[\]).forEach(p => {
parents.push({ name: p.driveItem && p.driveItem.title, id: (p.driveItem && p.driveItem.name || '').replace('items/',''), time: act.timestamp });
});
}
});
});
pageToken = resp.nextPageToken;
} while (pageToken);
return parents; // sort by time; the earliest removedParent is usually the original
}
```
Note: `query` works at the *item* or *ancestor* level — pass `ancestorName: ‘items/’` instead of `itemName` to sweep a whole folder tree in one query rather than per-file.
**2. Move a file back** (Drive v3 uses addParents/removeParents, not setParents):
```javascript
function moveFile(fileId, newParentId) {
const current = Drive.Files.get(fileId, { fields: ‘parents’ });
Drive.Files.update({}, fileId, null, {
addParents: newParentId,
removeParents: (current.parents || \[\]).join(','),
fields: 'id, parents'
});
}
```
**3. List + roll back revisions:**
```javascript
function listRevisions(fileId) {
let revs = [], pageToken;
do {
const r = Drive.Revisions.list(fileId, { pageToken, fields: 'revisions(id,modifiedTime,keepForever),nextPageToken' });
revs = revs.concat(r.revisions || \[\]);
pageToken = r.nextPageToken;
} while (pageToken);
return revs; // pick the one with modifiedTime just before your Mid-March disruption
}
```
Important reality check on rollback: the Revisions API can **read/download** an old revision and let you **pin** it (`keepForever`), but for Google-native Docs/Sheets/Slides there’s no API call that “reverts the live document to revision X.” For those you either restore manually via File → Version history, or export the old revision’s content and write it back. Binary files (PDFs etc.) you can re-upload the old revision’s bytes as a new version. So the API is great for *identifying* the right revision and exporting it; the actual revert for native files is partly manual.
Given the 30-day binary-revision window, the first thing I’d do today is run `listRevisions` across the affected files and call `Drive.Revisions.update` to set `keepForever: true` on the pre-disruption revisions, so you stop the clock before anything else.