Hashim Adel
Hashim Adel

Reputation: 735

creating account by data from spreadsheet - google apps

I am working on a simple script that creates an account in the control panel of a domain - for example Gmail - and I was looking for a function in the Google apps script that creates an account automatically on inserting data to a spreadsheet

I searched the internet and I did find this though : https://developers.google.com/apps-script/class_usermanager and the method I am using is : var user = UserManager.createUser("john.smith", "John", "Smith", "password My question is, how can I insert the parameters from the spreadsheet that I have. Sorry if this sounds a bit stupid I'm just new to Google apps script.

Upvotes: 0

Views: 107

Answers (1)

Phil Bozak
Phil Bozak

Reputation: 2822

To read from the spreadsheet, you would use the SpreadsheetApp.

An example of reading a set of rows. (Let's say all rows).

var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();

.getValues() returns a 2D array. So you would access it by data[rowNum][colNum]. Let's say you want to add every row as a new user, you could do

for (var i in data) {
  UserManager.createUser(data[i][0], data[i][1], data[i][2], data[i][3]);
}

How would you run said script? You could put all of it inside some function (function addAllUsers()) and then run it from the run menu in the Script Editor.

Upvotes: 1

Related Questions