Google Apps Script

Class UiApp

Create user interfaces for use inside Google Apps or as standalone services.

Properties

PropertyTypeDescription
DateTimeFormatDateTimeFormatConstants to use with setFormat methods in UiApp widgets such as DatePicker and DateBox.
FileTypeFileTypeConstants to use with UiApp.createGoogleDocsPicker(); DatePicker and DateBox.
HorizontalAlignmentHorizontalAlignmentConstants to use with setHorizontalAlignment methods in UiApp.
VerticalAlignmentVerticalAlignmentConstants to use with setVerticalAlignment methods in UiApp.

Methods

MethodReturn typeBrief description
createApplication()UiInstanceCreate a new UiInstance, which you can use to build a UI.
getActiveApplication()UiInstanceGets the active UiInstance.
getUserAgent()StringReturn the browser user-agent string, so that you can tailor your app as needed.

Detailed documentation

createApplication()

Create a new UiInstance, which you can use to build a UI.

Use this in the entry point of your app to create a UI. For example:

 
function doGet(e) {
   var app = UiApp.createApplication();
   // Create a button tied to a server click handler.
   app.add(app.createButton('Click me!', app.createServerHandler('onClick')).setId('button'));
   // Create a button tied to a client click handler.
   app.add(app.createButton('Click me too!',
       app.createClientHandler().forEventSource().setText('Clicked!')));
   return app; // If you don't return the UiInstance, the change won't happen
 }

 function onClick(e) {
   var app = UiApp.getActiveApplication();
   app.getElementById('button').setText('Clicked!');
   return app;
 }
 

Note that you cannot return a new UiInstance in an event handler from an existing UiInstance.

Return

UiInstance — a new UiInstance.


getActiveApplication()

Gets the active UiInstance.

Use this in the context of an event handler to interact with the existing UI. For example:

 
function doGet(e) {
   var app = UiApp.createApplication();
   app.add(app.createButton('Click me!', app.createServerHandler('onClick')).setId('button'));
   return app;
 }

 function onClick(e) {
   var app = UiApp.getActiveApplication();
   app.getElementById('button').setText('Clicked!');
   return app;  // If you don't return the UiInstance, the change won't happen
 }
 

Return

UiInstance — the active UiInstance.


getUserAgent()

Return the browser user-agent string, so that you can tailor your app as needed.

Return

String — the user-agent string.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.