Hi Tom,
This is something I did struggle with for many years (especially the compatibility control from going from one DOM version to another when my software updates).
My solution after a lot of trial and error was to use a custom library and try to keep each function as single responsibility (this also helps me make sweeping changes to all my code without breaking anything). By doing this I can wrap my function into a particular DOM version if the function is no longer supported after an InDesign update.
For example:
function BE_pageItemDelete(pageItemLabel) { // Initiate version control var currentDomVersion = app.scriptPreferences.version; var neededDomVersion = "6.0"; // This is the version number that is needed to run the encapsulated code if (neededDomVersion !== app.scriptPreferences.version) { currentDomVersion = app.scriptPreferences.version; BE_domVersion(neededDomVersion); } // Function script app.activeDocument.pageItems.item(pageItemLabel).remove(); // Reverse version control if (currentDomVersion !== neededDomVersion) { BE_domVersion(currentDomVersion); } } function BE_domVersion(version) { app.scriptPreferences.version = version; }
Because DOM version > 6.0 doesn't support script labeling I need to force the DOM to 6.0 and reset it back to the original DOM version after the function runs. I don't know if this is a good or elegant method in the real world but it works for my workflow processes.
Brett