How do I get the current file's name in Google Script?

.getActive().getName(); would be pretty effective.

SpreadsheetApp doesn't refer to a specific spreadsheet, you need to specify one then get the name, hence the getActive().


If you want to get the name of the spreadsheet that you are running the script from use:

var name = SpreadsheetApp.getActiveSpreadsheet().getName();

This solution works for all types of Google apps files (Docs, Sheets, Forms, ...)

You need to use DriveApp

The below code refers to Form, for instance:

const currentForm = FormApp.getActiveForm()
const formFile = DriveApp.getFileById(currentForm.getId())
const formName = formFile.getName()

Just get the document from the corresponding app, then use DriveApp to get the file by its ID, after that you will have the file name