I am trying to create a script that will read a date from the content of a file and then use that date to store the document in the appropriate group.
The JXAscript I created is the following:
let db_name = "_";
// Create a path based on the date.
function output_path(date) {
// For simplicity just return a fixed path
return "/BTW/top/2025/Q4/example";
}
// Log both to console and to DT
function log(msg) {
const app = Application("DEVONthink");
app.includeStandardAdditions = true;
app.logMessage(msg);
console.log(msg);
}
// Move the record to the specified path
function moveRecord(record, path) {
const app = Application("DEVONthink");
app.includeStandardAdditions = true;
const db = app.databases[db_name];
let group = app.createLocation(path, {in: db});
let originalGroup = record.locationGroup();
log('Moving from: ' + originalGroup.name());
log('Moving to: ' + group.name());
app.move({record: record, from: originalGroup, to: group});
log('Moved');
}
function scriptoutput(record, date) {
const app = Application("DEVONthink");
app.includeStandardAdditions = true;
log('Record: ' + record.name());
log('Detected date: ' + date);
const path = output_path(date);
log('Path: ' + path);
moveRecord(record, path);
log('---');
}
(() => {
let app = Application.currentApplication();
let dt = Application('DEVONthink');
app.includeStandardAdditions = true;
const appName = app.properties()["name"];
if (appName !== 'DEVONthink') {
const records = dt.selectedRecords();
console.log('Found ' + records.length + ' records');
records.forEach(function(record) {
// Fake the date
scriptoutput(record, "23-07-2023");
});
}
})()
When I run this script from Script Editor, I get the following output in the DT log window:
15/01/2026, 23:22:36: Record: Example Document
15/01/2026, 23:22:36: Detected date: 23-07-2023
15/01/2026, 23:22:36: Path: /top/2025/Q4/example
15/01/2026, 23:22:36: Moving from: archive input
15/01/2026, 23:22:36: Moving to: example
15/01/2026, 23:22:36: Moved
15/01/2026, 23:22:36: ---
This command runs as expected and moves the document to its destination.
However, when I run this script from the Smart Rule, I get the following output in the DT log window:
15/01/2026, 23:28:21: Record: Example Document
15/01/2026, 23:28:21: Detected date: 30-11-2024
15/01/2026, 23:28:21: Path: /top/2025/Q4/example
15/01/2026, 23:28:21: Moving from: archive input
15/01/2026, 23:28:21: Moving to: example
15/01/2026, 23:28:21: Scan and archive on scriptOutput (Error: Error: Can't convert types.)
The log shows that the script is failing on the line:
app.move({record: record, from: originalGroup, to: group});
As far as I can tell all elements, being the record, the originalGroup and the group are identical.
What can be causing this difference in behavior?