The following Google Apps Script code is designed to return the relevant card based on the error code value from the getDetails function. If 0 then all is fine and a card displaying student data is shown as confirmation before providing a way to run the makeTheCopy function for saving the email to Drive. If 1, 2, 3 or 5 is returned then a card specifying the error is returned to the user.
Success card displaying found student details |
We pass through the student details as input parameters and then proceed to build an add-on card in the same way we did when first opening the add-on (blog post). 3 card sections are created in total: displaying the found name and userId, a button for saving the email and another for a back button to re-enter a username.
The Save Email button is set to run the makeTheCopy function detailed in the next blog post and it passes through the input parameters so they can be re-used:
var saveButtonAction = CardService.newAction()
.setFunctionName('makeTheCopy')
.setParameters({userId: userId, forename: forename, surname: surname, folderId: folderID});
showCard function
In this instance we only pass through the error code value so that we can evaluate it and return static text informing the user of the problem. To do this, when creating a card section an if/else if statement has been used to select the text for a 'newTextParagraph' widget which is added to the card section. By using the same variable errorText whichever if statement evaluates as true sets the value for this variable:
if (errorCode == 1) {
var errorText = CardService.newTextParagraph().setText('Username was not found');
section1_1.addWidget(errorText);
}
No comments:
Post a Comment