Thanks for the suggestion. I improved little.
/**
* @param {globalThis.DocumentApp.Document} doc
*/
function getListIds_(doc) {
return doc.getBody()
.getListItems().reduce((a, c) => {
const id = c.getListId();
if (a.indexOf(id) === -1) a.push(id);
return a;
}, []);
}
/**
* @param {globalThis.DocumentApp.Document} doc
* @param {number} index
*/
function uncheckListById_(doc, id) {
const body = doc.getBody();
const lists = body.getListItems()
.filter(l => l.getListId() === id);
const last = lists.splice(-1)[0];
lists.reverse().forEach(item => {
const copy = last.copy();
copy.asListItem().setText(item.asListItem().getText());
body.insertListItem(0, copy);
item.removeFromParent();
});
}
function run() {
uncheckListById_(DocumentApp.getActiveDocument(), 'kix.yy1s6bgaip7h');
}
function printListIds() {
console.log(getListIds_(DocumentApp.getActiveDocument()));
}
The code doesn't support styles of paragraphs. But it works fine as a first approximation.
Best, Alex.