Skip to main content
1 of 2

Displays data arrays with appendrow where other columns contain data

I wrote a script to display a list of names and folder IDs.

The script that I wrote like this:

function listFolders() {

var sheet = SpreadsheetApp.getActiveSheet();
  sheet.getRange('A2:B').clear();
  //sheet.appendRow(["Name", "Folder-Id"]);

var folderID = DriveApp.getFolderById("1Hp_dM8WR0mGDT5q-a-VS-VVtl5dNCLfe");
var contents = folderID.getFolders();

var cnt = 0;
var lFolder;

while (contents.hasNext()) {
    var lFolder = contents.next();
    cnt++;

       data = [
            lFolder.getName(),
            lFolder.getId(),
        ];

         sheet.appendRow(data);
    };
};

I want to add new data in column C. After I fill in a text in column C, then I run the script. But the second row is empty.

enter image description here