grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

getting the id of a new document created #126

Closed rmrbytes closed 3 years ago

rmrbytes commented 3 years ago

I am able to create document from a Google Sheet

Something like this

const firestore = FirestoreApp.getFirestore(email, key, projectId);
 ...
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheets = ss.getSheets();
 var sheet = ss.getActiveSheet();

 var data = sheet.getDataRange().getValues();
 var parentid = '';
 var childid = '';
 for (i = 1; i < data.length; i++) {
    var title = data[i][0];
    const docjson = {
      'title': title
    };
    parentid = firestore.createDocument('collection1', docjson); 
    // this gives an error
  }

Explain the Problem in Detail

I would like the generated id because I would like to use it to dynamically create a subcollection

Library Version:

33

Thanks

rmrbytes commented 3 years ago

Oh. It does generate a json. My bad.