Monday 4 February 2019

Save email to Drive add-on - get user info

Overview blog post.

The following Google Apps Script code extracts the entered username from the event data and saves it as a variable:
var userId = e.formInput['userId'];
It checks to make sure the value is not blank before proceeding (ie the user has not just clicked the submit button) otherwise nothing else will occur. If a value has been entered we then call the getDetails function detailed in the next blog post, to get the corresponding name and folder ID. As this returns an array of student data we can then split the values appropriately - meaning we only need to interrogate the spreadsheet data once throughout the add-on:
var forename = details[0][0];
var surname = details[1][0];
var folderID = details[2][0];
var errorCode = details[3][0];
Next we need to determine the status of the error code in order to run the appropriate showCard(0) function, so we use an if statement. If the value is 0 then we run the showCard0 function and pass the above parameters through:
if (errorCode == 0) {
      Logger.log('errorCode is 0');
      //run showCard '0' function
      return showCard0(userId, forename, surname, folderID);
Else if the value is 1, 2, 3 or 5 we run the showCard function:
else if ( (errorCode == 1) || (errorCode == 2) || (errorCode == 3) || (errorCode == 5) ) {
      Logger.log('errorCode is: ' + errorCode);
      //run showCard function
      return showCard(errorCode);

No comments:

Post a Comment