I'm using Google App Script. I want to reassign my Global variable named myname. I had reassigned the value of myname to Testing Name. It assigns the value to myname on click of Set Name Button as I console in the handleSetName function. But when I got the value of myname on the handleGetName function it's getting undefined. I had pasted the code below and attached the logger image so that you can see output.
How can I reassign global variables?
Can anyone guide me on this?
Code.gs
var myname = "";
function loadMTS(event) {
const button1 = CardService.newTextButton().setText("Set Name")
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setOnClickAction(CardService.newAction().setFunctionName("handleSetName"));
const button2 = CardService.newTextButton().setText("Get Name")
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setOnClickAction(CardService.newAction().setFunctionName("handleGetName"));
return card.addSection(CardService.newCardSection().addWidget(button1).addWidget(button2)).build();
}
function handleSetName(e) {
myname = "Testing Name";
console.log("Name after change in handleSetName Fucntion :", myname);
}
function handleGetName(e) {
console.log("Name : ", myname);
}