I have managed to run the rule On Import by moving the evaluation of the custom metadata Status from the rule into the JavaScript:
function performsmartrule(records) {
const app = Application("DEVONthink 3");
app.includeStandardAdditions = true;
/* Loop over the records selected by the smart rule */
records.forEach(r => {
if (app.getCustomMetaData({ for: "status1", from: r }) == "ready to be renamed") {
app.logMessage("rename document");
renameDocument(r)
app.addCustomMetaData("renamed", { for: "status1", from: r })
}
})
}
Thank you for your help.