"lookup records with tags" fails in JavaScript only

This (AppleScript)

tell application id "DNtp"
	lookup records with tags {"Balkone"} in (get database with uuid "0EBFA252-7F46-4AB3-BCAF-B36410685E0B")
end tell

works as expected, returning a non-empty list of records. Whereas this (JavaScript)

const app = Application("DEVONthink 3");
const records = app.lookupRecordsWithTags(['Balkone'], {in: app.getDatabaseWithUuid(`0EBFA252-7F46-4AB3-BCAF-B36410685E0B`});

does not, in that it returns 0 records.
More precisely, Script Editor’s “Events” tab tells me this

app = Application("DEVONthink 3")
  app.getDatabaseWithUuid("0EBFA252-7F46-4AB3-BCAF-B36410685E0B")  
  app.lookupRecordsWithTags([], {in:app.databases.byId(3)})

which is obviously utter nonsense: I’m passing in an array with exactly one element, not an empty array. Something seems to be amiss here, I guess. @cgrunenberg ?

I can only confirm the nonsense, I used an internal build and DEVONthink indeed receives an empty array.

1 Like

I’m trying to convert my AppleScript scripts to JavaScript, and I’m having trouble with app.lookupRecordsWithTags method, as it’s returning null. Is it broken, or does someone have a fix?

What does your code look like?
Edit Not important. That’s a bug in the scripting interface: The method gets passed an empty array.
In Script Editor

(() => {
  const app = Application("DEVONthink 3");
  const r = app.lookupRecordsWithTags(['MyTag'], {in: app.databases['MyDatabase']});
})()

Events:

  app = Application("DEVONthink 3")
  app.lookupRecordsWithTags([], {in:app.databases.byName("Bru6")})

Well, that’s that. @cgrunenberg would have to comment on it, as he knows all the details about the scripting interface.

Alternative code

(() => {
  const app = Application("DEVONthink 3");
  const tagslist = ['Tag1, Tag2, Tag3'];
  const r = app.search(`any: tags: ${tagslist.join(';')} scope:MyDatabase`);
  console.log(r.length);
})()

Just use search instead of lookupRecordsWithTags. Until the latter gets fixed.

Note:

  • tags must be passed to search as a string, separated by semicolon
  • to find records matching any of the tags, prefix the search string with any:. Otherwise, it’ll only find records having Tag1, Tag2 and Tag3 set!