Hi Thom, thanks for your answer! But I change my code as below, but after running the script, there is an error: "NotAllowedError: Security settings prevent access to this property or method. Collab.reviewersEmail:-1:Console undefined:Exec", can you kindly advise?
var BMDestination = new Array();
var root = this.bookmarkRoot;
for (var i = 0; i < root.children.length; i++)
{
root.children.execute();
BMDestination.push({bk:root.children, page:this.pageNum});
}
BMDestination.sort();
for (var i = 0; i < root.children.length; i++)
{
root.insertChild(BMDestination);
}
Are you running this code in the Console Window?
Have you done any debug to determine on which line the error occurs? The error is not a real error message. It is either extraneous, as Try suggests, or there is an internal bug that is reporting the wrong error. This happens quite frequently since security changes were made to Acrobat a few versions ago. Either way you need to determine the line that is causing it.
Have you checked the results of the sort operation? I doubt it is sorting correctly. Since the array contains objects, you'll need to pass a helper function into the sort function for determining which object is greater or lesser. Look up the sort function in the Core JavaScript reference online.
There is nothing obvious in the code that would cause an error, but the final loop really should use the length of BMDestination for the increment limit, instead of the root.children since the loop is working on the bookmarkroot. Its possible that something dynamic is happening to the root.children that is causing the error.