Help needed with JS for templater script (2)


I’m still stuck on my templater script, to create automated Highlight notes.
I explained my workflow here and @ninjineer helped a lot with some very good advices.

As it was kind of wild for me that time, I did not have the time, to follow up this issue. But now, I want to continue solving that problem.

The last unsolved problem in that script is, that in the end it doesn’t create a new file. There must be a problem with the “tp.file.create_new”-function…

Templater script

//If you're working with note `report-today` in folder `reports` which is in 
//the `projects` folder which is the root level of the vault:
const template = tp.file.find_tfile('highlight-note template');
const path = tp.file.path(true);
//Returns the note file's path relative to the vault root. It includes the 
//file's `.md` extension
console.log(`path = '${path}'`);
//path = 'projects/reports/'

const slash = path.lastIndexOf('/');
//This command looks for the first `/` character starting from the end of the 
//string and returns its position in the string. To the right of this location 
//is the note's file name. To the left is relative path within the vault where
//where that note is kept. `lastIndexOf` will return -1 if the search string 
//is not found in the source string, which here means the note file is located
//in the vault's root folder.
console.log(`slash = ${slash}`);
//slash = 16

let folder = '';
//Empty string here represents the root folder of the vault;

if (slash > 0) folder = path.slice(0,slash+1);
//If a `/` was found, chop off the file name portion
// ... geht auch einfacher, nämlich wie in der templater doc zu lesen:
console.log(`folder = '${folder}'`);
//folder = 'projects/reports/'
let i = 1;
let new_filename = folder + tp.file.title + "_H"

while(await tp.file.exists(new_filename + i + ".md")) { 
	if (i === 100) {
		console.log("too much iterations");
let filename = `${tp.file.title}_H${i}`;

await tp.file.create_new(template, filename, false, folder);

tR += `![[${filename}]]`;

And here the console log:

plugin:templater-obsidian:61 Templater Error: Couldn’t create markdown file. e.getParentPrefix is not a function

log_error @ plugin:templater-obsidian:61
errorWrapper @ plugin:templater-obsidian:83
await in errorWrapper (async)
create_new_note_from_template @ plugin:templater-obsidian:3588
eval @ plugin:templater-obsidian:2411
eval @ VM228:100
await in eval (async)
eval @ plugin:templater-obsidian:3455
handleError @ plugin:templater-obsidian:3242
imports.wbg.__wbg_call_168da88779e35f61 @ plugin:templater-obsidian:3454
$func105 @ 00032406:0xa737
$func27 @ 00032406:0x5c9b
$renderer_render_content @ 00032406:0x8cd8
render_content @ plugin:templater-obsidian:3379
parse_commands @ plugin:templater-obsidian:3511
parse_template @ plugin:templater-obsidian:3553
await in parse_template (async)
read_and_parse_template @ plugin:templater-obsidian:3548
await in read_and_parse_template (async)
eval @ plugin:templater-obsidian:3639
errorWrapper @ plugin:templater-obsidian:80
append_template_to_active_file @ plugin:templater-obsidian:3639
onChooseItem @ plugin:templater-obsidian:2262
t.onChooseSuggestion @ app.js:1
t.selectSuggestion @ app.js:1
e.useSelectedItem @ app.js:1
(anonymous) @ app.js:1
e.handleKey @ app.js:1
e.onKeyEvent @ app.js:1

What does this console log mean? Why wasn’t it possible to create the new file?

Thanks in advance,
kind regards,