Thursday 31 January 2019

Save email to Drive add-on - get username

Overview blog post.

The following Google Apps Script code is the first to be run when the Gmail add-on is launched and is designed to prompt for a username of a student. The script is called via the 'onTriggerFunction' in the manifest file.
Screenshot of the username prompt for the email add-on
Save message to Drive add-on
We begin by building the card that requests this information and do so via the 'CardService.newCardBuilder' class, to which we need to create a 'newCardSection' to display our information. Next we create a 'textInput' widget to ask for the username:
var inputWidget = CardService.newTextInput()
    .setFieldName('userId')
    .setTitle('Enter username here')
Then add this to the section we created:
section.addWidget(inputWidget);
Now we need a button action, a button to attach the action to and to add it to the card section. The action for the button is to run the getUserInfo function detailed in the next blog post. The button itself just contains the text Submit.
var buttonAction = CardService.newAction()
    .setFunctionName('getUserInfo');
var button = CardService.newTextButton()
    .setText('Submit')
    .setOnClickAction(buttonAction);
var buttonSet = CardService.newButtonSet()
    .addButton(button)
The final part of this script finishes by adding the buttonSet widget to the section, the section to the card, then 'build' the card and return it.

No comments:

Post a Comment