JXA Sometimes Importing to Wrong Location

** Just discovered a major clue

On my Mac where the API uploads go only to the database inbox of several long-term production databases…

I created a brand new database with several groups and subgroups.

I changed nothing else about the configuration of DT3 or my computer.

It works perfectly in the new database by uploading to the desired group or subgroup.

If I try it with the original databases it still goes only to the database inbox with the API/Python (but to the proper Group with the direct JXA script)

All databases verify without error

Very interesting … what might be different about the databases where it does not work?

1 Like

I suppose that

is a question for @cgrunenberg. I’m out of ideas.

Python string-handling codecs ?

(String interpretation settings are a dimension in which ostensibly identical Python installations may subtly differ)

Any utf8 characters in the DEVONthink (or file-system) path names which go beyond the narrow ascii set ?

Please post the latest version of your script.

Seems to be here:

running it via osascript like so

osascript -l JavaScript scriptfile "yourfile" "yourUUID" "" ""

seems to work with one database, but not with the other.

Though that might be an idea, I think it does not apply here. The UUIDs are ASCII only, and the script fails (at least with one database/group) with osascript, too. No python involved, there.

I wonder whether it fails in the Script Editor.app too using the same arguments. Checking the arguments might be a good idea too.

I just took the code in post # 20 JXA Sometimes Importing to Wrong Location - #20 by 8isnothing and placed it in Script Editor as Javascript

I inserted the parameters including the UUID to a group in my longstanding main database. When I run the script, the file is added to the Inbox of the longstanding database. (So it fails there.)

Then I changed nothing except I changed the UUID to a group in my newly created test database. When I run the script like that, the file is added correctly to the desired Group.

Could you please _print _ the uuid with console.log and check that it is correct in both cases? Also, a screenshot of the Apple events would be helpful (again, in both cases)

OK this is for the older database where the file goes to the database Inbox:

And this is for the newer database where the file goes correctly to the selected group:

Cool. Or rather not – it looks completely ok in both cases. The only thing that I could think of to verify is

console.log(`${myDestGroup.uuid()} - ${myDestGroup.type()}`);

but that will probably also return the correct UUID and hopefully “group” for the type. @cgrunenberg would then have to weigh in on the question when the import(...{to: ...}) could go to the inbox instead of the group itself.

Also for comparison… using Script Editor and the same UUID this script ** does ** result in the file being inserted into the correct group in both the older and newer databases:

function run() {
	app = Application.currentApplication(); app.includeStandardAdditions = true;

	dt = Application("DEVONthink 3"); dt.includeStandardAdditions = true;
	
	var dtUUID = app.displayDialog("Insert UUID (not x-devonthink-item link):", {
		defaultAnswer: "",
		buttons: ["Cancel","Continue"],
		defaultButton: "Continue"
	})

	var document = app.chooseFile({
		withPrompt: "Please select a document to import:"
	})
	
	var destRecord = dt.getRecordWithUuid(dtUUID.textReturned)
	dt.import(document.toString(), {to:destRecord})
}

I can’t reproduce the issue, the script works fine here using item links (since version 3.7.2 supported by get record with UUID) for groups in various databases

Yes - that gives the expected output - though again it goes to the database inbox:

Again - it works fine for me too ** with a new database **.

What could be different about all of my older databases so that the behavior is different for those?

As long as a verification of the database is fine, I can’t tell. Or only if you’ll send us a copy of this database.

OK - the example UUID I posted where it goes to the database inbox is on a database which is for me but has no client data so I can send you privately a copy of that. Thanks.

Just send me a download link after uploading a Zip archive (ideally exported via File > Export > Database Archive…) to a cloud service, thanks.

OK done- many thanks for your help

This line causes the issue:

myImportedRecord.tags = myTags

Your groups are not excluded from tagging (see File > Database Properties), therefore by importing the file to a group the record gets a tag (the group’s name) and setting no or different tags afterwards removes the record from the group again.

In case of a new database groups are by default excluded from tagging.

2 Likes