Upload data on Google Sheet and Download

Goodmorning everyone!
I use the following formula to upload specific data to Google Sheet.

It works perfectly.
It is a description written in a Multiline TextBox.
The problem is that when I go to read the data from Google Sheet, even if I use the Json Decode, the prefix (\ n) does not translate it correctly and writes it as \ n

I also tried with UriEncode, but even worse

You do not show "how" you are uploading data to the google sheet?

Also, not too sure why you need to use the JsonObjectEncode block ?

I used the process described in this video for the upload

I believe there may be issues with only using appendRow when sending data with line returns to a cell. There is a solution to this - I just have to find it.

For a doGet(e):

The following works for both situations in a multiline textbox, whether you use \n or actually press return for a new line...also works if you do not enter a line return of either type.

google apps script:

function doGet(e) {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet1');
  var data = [];
  var tba = JSON.parse(e.parameter.tb1).join('\r\n');
  var tbb = JSON.parse(e.parameter.tb2).join('\r\n');
  data = [tba,tbb];
  sh.appendRow(data);
  return ContentService.createTextOutput(data); 
}

image

You can also use doPost(e) if you type \n and DO NOT press for a line return

function doPost(e) {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet1');
  var data = [ ];
  var data = JSON.parse(e.postData.contents);
  sh.appendRow(data);
  return ContentService.createTextOutput(data); 
}


(I have not figured out a way to handle both types of line return yet for doPost(e), but I expect it would be fairly similar to the doGet(e) one)

Hmmm, seems my previous effort was more by luck than judgement. The textbox exhibits some strange behaviour when you include an \n in the text, e.g. one\ntwo\nthree, in that the \n cannot be found with contains or split by, whereas when you press Enter to return a new line you can find that \n.

A bit more work to do....

Have a better, more rounded solution to handle inline (`one\ntwo\nthree) and user Enter pressed line returns, for both doGet(e) and doPost(e).

It is necessary to convert both types of strings with line returns to lists (arrays) in AppInventor, and to then convert these lists back to strings with line returns in the google apps script. This is due to the way textboxes and text blocks handle typed in \n and non typed in \n - with one being treated as text, the other being treated as a non printing line return (the same with Enter pressed line returns). To overcome this I have created a small procedure that handles both scenarios, and converts the textbox string to a list, to send to the google apps script, and then on to the spreadsheet.

doGet(e)

function doGet(e) {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet1');
  var data = [];
  var content = e.parameter;
  for (var k in content) {
   var cell = JSON.parse(content[k]);
   data.push(cell.join('\r\n')); 
  }
  sh.appendRow(data);
  return ContentService.createTextOutput(data); 
}

doPost(e)

function doPost(e) {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet1');
  var data = [];
  var content = JSON.parse(e.postData.contents);
  for (var i=0; i<content.length; i++) {
    data.push(content[i].join('\r\n'));
  }
  sh.appendRow(data);
  return ContentService.createTextOutput(data); 
}

Thank You very much TIMAI2!
I will try in the next days