Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We’ve created a simple example form. Select the employee, a location and a new extension number. Click the Update Google Sheet button, wait a few seconds and see that the sheet was successfully updated. We did this using this rule:

var x;
Code Block
languagejs
if (ConnectUpdateGoogleSheet.clicked) {

       var headerseid = ‘ {“
            user”: ”sales @frevvo.com”,
            ”password”: ” < access token > ”
        }’;
        var readqueryEId.value; // Unique key in the Google Sheet row

var headers = ‘{“user”:”<google id>”,”password”:”<access token>”}’;

var updatequery = ‘/google/spreadsheets / query update/ key / < spreadsheetkey > /w/Employees’;
        eval(‘x = ’+http.get(readquery, headers));

        var opts = [”];
        for (var i = 0; i < x.results.length; i++) {
            opts[i + 1] = x.results[i].employeeid + ‘ = ’+x.results[i].firstname + ‘‘ +x.results[i].lastname;
        }
        EId.options = opts;
    }/<spreadsheetkey>?wsname=Locations&query=employeeid=”‘ + eid + ‘”‘;

var updateparams = ‘&updates=location=’ + Location.value + ‘,extension=’ + Extension.value;

eval(‘x=’ + http.put(updatequery + updateparams, null, headers, false));

}
  1. It’s triggered by clicking on the Update Google Sheet button.
  2. We setup headers and an update query using your access token and spreadsheet key (the long ID in the URL of the Google Sheet).
  3. Add updateparams: we’re updating location and extension with new values.
  4. Run the update – perform an http.put() and eval the results.

...