How can I use the filename in the note AFTER I enter the title?

At the very start of your template you need to detect whether the file is named “Untitled” or similar, and change it before you move on to the rest of the template. An example on how to do this is given in the thread below: