I have a list of Google Apps users in a spreadsheet that I want to wash against the UserManager service to make sure what’s in the spreadsheet is correct. Is there any way to determine if a user exists so that the script can continue running without a fatal exception? At the moment. if I execute something like:
var userID = "foo";
var ga = UserManager.getUser(userID).getEmail();
And foo doesn’t exist, Apps Script halts and returns:
Bad request: EntityDoesNotExist(1301): foo (line 34)
It’d be nice to be able to handle this more cleanly so that the script can continue running by doing something like:
var userID = "foo";
var ga = UserManager.getUser(userID).getEmail();
if (ga.exists == true) {
// update
} else {
// create
};
Thanks for your help!
You can use try/catch to check if there’s an error and continue:
http://www.w3schools.com/js/js_try_catch.asp