I have a Google form that submits data to a Google Sheet. I have set a time-based event to run a Google App Script, within the spreadsheet, every 10 minutes for testing purposes. The script takes data in the spreadsheet and updates users' information (Job Title, etc.) in our Google Apps Directory
Now, when I test the script in the dev console, it works perfectly. When I debug it, there are no bugs. If I run it from a trigger I get the error:
Anyone know a reason why it would work if I run the function but not when time-based trigger works?
Here is the code:
// Update user's job title
function updateTitle(userEmail, userTitle, userDept, userLocation) {
var update = {
organizations:
[{
name: "Our Org",
title: userTitle,
primary: true,
type: "work",
department: userDept,
location: userLocation
}]
};
AdminDirectory.Users.update(update, userEmail); // <-- LINE 14
}
// Get the users email from spreadsheet
function getData(){
var SS = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = SS.getLastRow();
var data = SS.getDataRange().getValues();
for(i = 1; i < data.length; i++){
var title = data[i][1].toString();
var email = data[i][2].toString();
var department = data[i][3].toString();
var location = data[i][4].toString();
updateTitle(email, title, department, location);
}
MailApp.sendEmail('my.email@org.com', 'It ran title update', 'Check it out ' + SpreadsheetApp.getActiveSpreadsheet().getUrl());
}