O
O
Osco2019-05-07 00:55:23
PHP
Osco, 2019-05-07 00:55:23

Write value to Google spreadsheet on button click from website?

Actually the whole point is in the question, but I will explain in more detail.
There is a table like this:
5cd0a978d1b56561912225.jpeg
There is a site that displays such plates based on a Google table (something like an electronic order board), the page is updated with simple js every 3 minutes:
5cd0aa910c6ae303121586.jpegNEED: by clicking on a button on a specific plate on the site, make a change to the corresponding row/cell of the table, suppose to change 0 to 1.
The whole point of this action is that when the value in the "status" column changes from 0 to 1, the plate from the site disappears, the order is completed (you can see this on the screenshots).
Using the poke method to display the data on the site turned out, but in the opposite direction, with the record, I just can’t figure it out, please help, kind people :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Stoyanov, 2019-10-18
@Osco

You need to create the doGet () function, implement the mechanism for changing data in the table in it, then deploy the script as a web application on your own behalf and available to all users on the Internet.
Next, on your site, hang an event handler on the button.
In it, you implement a request to your web application by passing the necessary data.
More or less like this

// В гугл таблице
function doGet ( e ) {
  var ss0 = SpreadsheetApp.getActiveSpreadsheet();
  var ss0_s0 = ss0.getSheetByName("Лист1");
  
  var row = e.parameter.row;
  var val = e.parameter.val;
  
  ss0_s0.getRange("B" + row).setValue( val );
  
  return true;
}



// У вас на сайте
$("#my-button-id").on("click", function () {
  var url = ""; // Тут указать url который получили при разворачивании веб приложения
  var row = 1; // Получить строку
  var val = "0"; // Получить данные

  // Отправить данные
  $.ajax({
    type: "GET",
    url: `${ url }?row=${ row }&val=${ val }`,
    dataType: 'jsonp',
    crossDomain: true,
    success: function ( data ) {}, // В случае успеха
    failure: function ( error ) {} // В случае провала
  });
});

---
Maxim Stoyanov (stomaks), developer of Google Apps Script .
g-apps-script.com
stomaks.me

M
MamaLuyba, 2019-05-07
@MamaLuyba

with google.sheets, I barely figured it out without half a liter, of course - but you have to figure it out.
I would be at home - I looked at my code on this topic, and so - see https://developers.google.com/sheets/api/reference...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question