Search code examples
google-apps-scriptgoogle-docs

Google App Script can't capitalise a variable using .toUppercase()


I have a variable defined:

var capitaliseMe = "this is an example";

I want to replace text in the header of a Google Doc with the capitalised form of this variable.

I tried using the following

header.replaceText("{{ReplaceMe}}", capitaliseMe.toUppercase());

but this doesn't seem to be working as I get the error

TypeError: capitaliseMe.toUppercase is not a function

There doesn't seem to be a comprehensive answer to this anywhere on Stack Overflow or elsewhere online, so some help with capitalisation would be much appreciated!


Solution

  • Try:

    header.replaceText("{{ReplaceMe}}", capitaliseMe.toUpperCase());
    

    C is case was not capitalized. Its called camel code.

    toUpperCase