I’m trying to make a script for my Google document so I can format specific paragraphs in some “chat log” segments according to the nickname the paragraph begins with (example: “myNickname: blah blah blah”).
I made a test function to test out findText() but when I execute test()
, it returns this error: ReferenceError: findText is not defined test @ Code.gs:21
Here is the complete script:
function onOpen(e) {
DocumentApp.getUi()
.createMenu("FORMATTING")
.addItem("Test", "test")
.addToUi();
}
function formatNickname(nickname, style) {
nickname = nickname + ":"; // Dialogue is in a 'chat log' format, so it's displayed as "NICKNAME: Blah blah blah"
let foundText = findText(nickname);
foundText.getText().setTextStyle(style);
console.log(foundText); // Debug
}
function test() {
formatNickname("BAB", findText("AA:").getText.getTextStyle()); // The second parameter is for debug reasons. AA is a character with a specific text style.
}
And here is my appsscript.json:
{
"oauthScopes": [
"https://www.googleapis.com/auth/documents.currentonly",
"https://www.googleapis.com/auth/documents"
],
"timeZone": "America/Sao_Paulo",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
I have Google Apps Script API turned on in my user settings, as instructed in this answer.