Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:37:39+00:00 2026-06-11T18:37:39+00:00

Hello everyone out there, I can use global variables within a handler function, however

  • 0

Hello everyone out there,

I can use global variables within a handler function, however I cannot modify them “globally” within than function.

In code below, after the first click it will show the number 1001 (the handler reads, increments and shows the right result).
But, any further clicks will always show 1001, so the handler keeps reading the original globalVar value: it doesn’t get modified as I was expecting.

Anything I can do to fix this?

var globalVar = 1000;

function testingGlobals() {
  var app = UiApp.createApplication();
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var panel = app.createVerticalPanel().setId('panel');
  app.add(panel);
  panel.add(app.createButton(globalVar).setId("globalVar").addClickHandler(app.createServerHandler("chgGlobal").addCallbackElement(panel)));
  doc.show(app)
}

function chgGlobal(e) {
  var app = UiApp.createApplication();
  globalVar++;
  app.getElementById("globalVar").setText(globalVar);
  return app;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:37:40+00:00Added an answer on June 11, 2026 at 6:37 pm

    You can not increment Global Variables this way, as every time a handler executes, Global variable is initialized and then manipulated.
    You can use hidden formfields to hold the a variable which you can change in handler, and it will be persistent as long as the app is open.

    e.g

    function testingGlobals() {
      var app = UiApp.createApplication();
      var doc = SpreadsheetApp.getActiveSpreadsheet();
      var panel = app.createVerticalPanel().setId('panel');
      var myVar = app.createHidden().setValue('0').setName('myVar').setId('myVar');
      panel.add(myVar);
      app.add(panel);
      panel.add(app.createButton('0').setId("globalVar").addClickHandler(app.createServerHandler("chgGlobal").addCallbackElement(panel)));
      doc.show(app)
    }
    
    function chgGlobal(e) {
      var app = UiApp.createApplication();
      gloabalVar = parseInt(e.parameter.myVar);
      gloabalVar ++;
      app.getElementById('myVar').setValue(gloabalVar.toString());
      app.getElementById("globalVar").setText(gloabalVar);
      return app;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello there everyone, I've been trying to figure out how to create a function
Hello everyone I can't seem to figure out why my emulator isn't working and
Hello everyone it's been some days that I use sql to make analysis and
Hello everyone :) I decided to try out Android SDK with NetBeans. I installed
Hello everyone please help me out regarding menu in android . i want to
Hello everyone please help me out regarding this this piece of code $user =
hello everyone plz help me out with this script. I am calling my pages
Hello everyone please help me out regarding this query which is fetching the data
Possible Duplicate: Find out which class called a method in another class. Hello everyone,
hello everyone I am trying to make a script that steps through a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.