I want to pass an object to a Google Sheet Web App that I have written and have that data appended to the Google Sheet. I want to make sure the data ends up in the correct columns.
I can append the data to the file, but this could cause issues if columns are added/maniputated etc.
I have created column metadata for each column that corresponds to the object key.
I can read through the column metadata and find what column number each one represents. ie. if I get the metadata for "orderNumber" i can see it is in row 1.
Code for web app.
function doGet(e) {
  var p = e.parameter;
  var sheetName = "Orders";
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  var appendList = JSON.parse(p.appendList)[0];
  var returnValue = {};
  returnValue["status"] ="error";
  //var appendRow = sheet.getLastRow()+1;
  var values = []
  for (var key in appendList) {
    values.push(appendList[key]);
    Logger.log(searchAndReturnCol(key+"Column")); // just to show I can get the column number from meta data
  }
  sheet.appendRow(values);
  return ContentService.createTextOutput(JSON.stringify(returnValue));
}
function testDoGet() { // emmulates what will past over by the app
  var e = [];
  var test = [{
    'orderNumber' : "vsdv",
    'name' : "Bob",
    'porkDumpling' : 0,
    'prawnDumpling' : 0,
    'vegetarianDumpling' : 0,
    'sauce' : "Spicey",
    'paymentMethod' : "Cash",
    'dollarReceivable' : 5,
    'dollarReceived' :5,
    'collectionDate' : 44234244,
    'packed' : "No",
    'collected' : "No",
    'comments' : "This is a comment"
  }]
  var mod = JSON.stringify (test)
  e.parameter = {
    'appendList':mod,
    }
  doGet(e)
  //displayLog (doGet(e));
}
Code to find metadata
function searchAndReturnCol (key){
  var colLevel = cSAM.SAM.searchByKey (SSID , key);
  return colLevel.matchedDeveloperMetadata[0].developerMetadata.location.dimensionRange.endIndex
}
What I am unsure about is how to bring the two ideas together. I want to check the key in the object and then make sure that this data is inserted into the correct column based on the column metadata.
 
    