I have a problem with app script. I try to add my data to Google Sheet but I can't do it. Firstly, I get my data from Firestore. It returns the Document or Document[] variables. So how can I access inside of this variable and write to my Google Sheet? I didn't find anything about for that. Here is my function:
function myFunction(){
var firestore = FirestoreApp.getFirestore (email, key, projectId);
const allDocuments = firestore.getDocuments("TEST");
console.log(allDocuments.length);
}
Can you help me please? How can I read that data and write to my Google Sheet?
The library page provides a link to the wiki, which contains a bit more info.
The getDocuments()
method returns an array of the documents in the collection. You just need to loop over this Array and do whatever you want with the documents in this array, e.g. update the Sheet cells.
For example, the following shows one possible approach to get the value of the field1
field for each document:
const allDocuments = firestore.getDocuments("TEST");
for (var i = 0; i < allDocuments.length; i++) {
var field1Value = allDocuments[i].fields["field1"];
// ...
}
Based on your update I guess you want to build an array and pass it to appendRow().
The following should do the trick:
const allDocuments = firestore.getDocuments("TEST");
var myArray = [];
for(var i = 0; I < allDocuments.length; i++){
var chills = allDocuments[i].fields["chills"];
myArray.push(chills.boolean);
}
sheet.appendRow(myArray);
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments