Post scripts to googles sheets

hello, I have a problem, it publishes only the user data, which I bring from the previous screen, but the publication block for the sheet is ordered as in the google sheet, in the same way in the scripts; in the first row I want the data of the moment of capture of the scan to come out and I have tried it manually with a button and registering it too, but there is no case, it repeats me only to put the user; where am I wrong thanks!
1


See here:

Simple Post and Get Data

You could rather use the GS Connected Extension by TIMAI2.

It lets you do many things related to Google Sheets.

Also, pls post things(here: blocks [change language before taking screenshots.]) in English, so that more people can understand what problem you are facing.


SHUBHAMR69  

Hello, I would not be at the level of knowledge to solve my problem; since in the case of TIMAI2
when copying the script it gives me an error since data is missing and I don't know how to place it. In the case of SHUBHAMR69 it is more complex since the aia model requires me to fill in the variables and the scripts is a lot of information for me. I would be grateful if someone could correct my proposal since if it sends data to the sheet; what I would not know because it does not send the rest and in fact what it sends is not typed like most of its examples but rather scanned that number that appears in cell 1 "26467400" was scanned and what I need there is the date and time of the capture, that the command I think is correct
// receiving scanned data from client i.e android app
var date = new Date()

thank you

1 Like

Try this google apps script:

function doPost(e) {
  var ss = SpreadsheetApp.openByUrl(<url to your spreadsheet here>);
  var sh = ss.getSheetByName('Sheet1');

  var data = JSON.parse(e.postData.contents);
  sh.appendRow(data);
  return ContentService.createTextOutput(data);  
}

putting your spreadsheet url in the correct place.

This will not add a date, but then you do not have a column for a date! I suggest the following:

  1. Add a column in your spreadsheet for a date
  2. Add a clock component from Sensors
  3. Generate formatted date/time as required to a variable
  4. Edit the postText to include the date variable
2 Likes

hello I was struggling with the concepts, in the first part it recognizes the word user in the first cell, which is a word in Spanish, following this logic the rest of the words such as telephone in Spanish I did not take it, so I tried with phone in English and if I take it, ok! the third column was the date but there was no case data, date, date I couldn't think of any more, and the fourth was price, quantity, $ that's it, now I upload something curious in the image, it is supposed to be in the text box in blocks the first column of sheets should go without ( & ) because it corresponds to the first cell and then to identify the others you should put (&) in each concept, it turns out that the last price if I put it according to logic nothing happens, Now if I remove it, it takes the indicated value 124, see in the attached image, that is, the data arrives but why does it not apply? What concept should I place? thank you..

and by the way use your timag scripts

1 Like

If using my script as above, you need to make a list:

image

don´t work thanks

All I can do is link you back to the guide.

I suggest you follow this from the beginning.

I tried it and I have null on sending data, what is my error?


You are using POST (doPost(e)). You do not need doGet(e).

Try this demo project, does this work for you ?

DemoPostData.aia (2.0 KB)

Google Sheet

Script

function doPost(e) {
  var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1wqQe6CkE0_T2Zfdx9qzox63XHm6LVzH-L6oT2JcRWn4/edit#gid=0');
  var sh = ss.getSheetByName('Sheet1');

  var data = JSON.parse(e.postData.contents);
  sh.appendRow(data);
  return ContentService.createTextOutput(data);  
}

For your web app, confirm that you have republished to a new version correctly, and that your script url in the app matches the script url when new version is created.

If things still do not work, post the full content of the html code error returned.

3 Likes

You cannot run the script in the script editor, because you are not providing any "post Data". You need to send (post) data using the AI2 app.

The use of single or double quotes should be interchangeable, but make certain they are the correct type of single or double quotes by typing them in after copying and pasting the script.

Also confirm your new versions are saved with the correct access:

New editor
image

Legacy editor
image

2 Likes

Is this definitely "Sheet1" ?

image

Are you sure that the spreadsheet url in your script is the correct one for the the spreadsheet, and you have published a new version of the script ?

Are you sure that the script url you are using in the app is the correct one ?

hello, it worked...a button appeared within google script that said NEW EDITOR, before I didn't have it and with so many tests it didn't appear,...and it appeared a few hours ago; I tried the first time, another block formation the one I brought before and it didn't work and I tried your formation again and it just worked,
I appreciate your patience and dedication, thank you very much, excellent commitment. Cheers

1 Like

Please to hear you finally got it working.

It should not make any difference as to which script editor you use. I use the old/legacy editor all the time without issue.

1 Like

ok, but that's how it was for me! in fact when I started this post; I used a script that did not send data completely but did send and did it with the old editor...!
Finally the issue is solved and I thank you again, regards

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.