Синхронизировать c все данные RealtimeDB в столбцы таблицы Google - PullRequest
1 голос
/ 14 июля 2020

Каждый раз, когда я добавляю или редактирую продукт через свое приложение, я пытаюсь записать данные Firebase RealtimeDB в электронную таблицу Google Sheets через Google Appscript.

Так выглядит мой RealtimeDB

enter image description here

And this is my goal for every product (ignore the blue box)

введите описание изображения здесь

Это то, что я делал до сих пор, но я не знаю, как обрабатывать диапазоны листов и добавлять данные в эти c позиции.

url="https://inventory-c1e.firebaseio.com/Items.json?&auh=pur6Ka8wYVAd" 
xpath="OMCPC150C/itembarcode"   //here im trying something but dont know how to continue for all DB values      
function addProduct() {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow([IMPORTJSON()]);
}
function IMPORTJSON(){
  
  try{
    
    var res = UrlFetchApp.fetch(url);
    var content = res.getContentText();
    var json = JSON.parse(content);
    
    var patharray = xpath.split("/");
    //Logger.log(patharray);
    
    for(var i=0;i<patharray.length;i++){
      json = json[patharray[i]];
    }
    
    //Logger.log(typeof(json));
    
    if(typeof(json) === "undefined"){
      return "Node Not Available";
    } else if(typeof(json) === "object"){
      var tempArr = [];
      
      for(var obj in json){
        tempArr.push([obj,json[obj]]);
      }
      return tempArr;
    } else if(typeof(json) !== "object") {
      return json;
    }
  }
  catch(err){
      return "Error getting data";  
  }
  
}

Итак пожалуйста, расскажите мне, как продолжить

...