JXA Sometimes Importing to Wrong Location

Here’s the JXA code, in case someone can help us test it (I’ve replaced the ‘length’ as suggested):

(Please notice that ‘myDirectory’ is the path to the file/folder to be imported.)

function run(args) {
	// app variables
	const dt = Application("DEVONthink 3"); dt.includeStandardAdditions = true;
	
	// Get args
	const myDirectory = args[0]
	const myDestUUID = args[1]
	var myTags =  args[2]
	var myCustomMeta = args[3]
	
	if (myTags == "") {
		myTags = []
	} else {
		myTags = JSON.parse(myTags)
	}
	
	if (myCustomMeta == "") {
		myCustomMeta = {}
	} else {
		myCustomMeta = JSON.parse(myCustomMeta)
	}
	

	
	if (myDestUUID != "") {  // Check if MyDest is set
		try {  // Check if myDestUUID exists
			myDestGroup = dt.getRecordWithUuid(myDestUUID)
		
			if (myDestGroup === null) {
				throw "Error"
			}
		} catch (e) {
			console.log("Couldn't find group with uuid " + myDestUUID)
			return Error("Couldn't find group with uuid " + myDestUUID)
		}
		var myImportedRecord = dt.import(myDirectory, {to:myDestGroup})
	} else { // Default import in case it isn't
		var myImportedRecord = dt.import(myDirectory)
	}
	
	myImportedRecord.tags = myTags
	myImportedRecord.customMetaData = myCustomMeta
	
	return myImportedRecord.uuid()
	
}