I see what you mean. Sorry, I misunderstood. The script tries to create only document-internal links, but the destination page can be in a different file. Here's the upgraded script.
Open all the documents, then run the script.
(function () {
var docs = app.documents.everyItem().getElements();
function findExternalPage (folio) {
for (var i = 0; i < docs.length; i++) {
if (docs[i].pages.item(folio).isValid) {
return docs[i].pages.item(folio);
}
}
return null;
}
function addLinks (d, cells) {
var page;
for (var i = 1; i < cells.length; i++) {
page = d.pages.item(cells[i].contents);
if (page.isValid) {
d.hyperlinks.add (
d.hyperlinkTextSources.add (cells[i].texts[0]),
d.hyperlinkPageDestinations.add (page)
);
} else {
page = findExternalPage (cells[i].contents);
if (page) {
d.hyperlinks.add (
d.hyperlinkTextSources.add (cells[i].texts[0]),
d.hyperlinkExternalPageDestinations.add (page)
);
}
}
}
}
function processDocument (d) {
var columns = d.stories.everyItem().
tables.everyItem().
columns.everyItem().
getElements();
for (var i = 0; i < columns.length; i++) {
if (columns[i].cells[0].contents === 'Page') {
addLinks (d, columns[i].cells.everyItem().getElements());
}
}
}
for (var i = 0; i < docs.length; i++) {
processDocument (docs[i]);
}
}());