...
...
Section | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
...
Code Block | ||
---|---|---|
| ||
/*member password, user*/ if (UpdateGoogleSheet.clicked) { var eid = EId.value; // Unique key in the Google Sheet row var headers = {"user":"<google id>","password":"<your access token>"}; var updatequery = '/google/spreadsheets/update/key/<your spreadsheet key>?wsname=Locations&query='+encodeURIComponent('employeeid="' + eid + '"'); var params ={"location":Location.value,"extension":Extension.value}; var updateparams = '&updatesupdatesjson='+encodeURIComponent('location='+Location.value+',extension='+Extension.valueJSON.stringify(params)); eval('x=' + http.put(updatequery + updateparams, null, headers, false, false)); } |
- It’s triggered by clicking on the Update Google Sheet button.
- We setup headers and an update query using your access token and spreadsheet key (the long ID in the URL of the Google Sheet). In this example, the name of the Google Sheet tab is Locations. Change the wsname= parameter to the name of your Google Sheet tab if you named the tab something different.
- Add updateparams: we’re updating location and extension with new values.var params to identify the column names and control values that will update them.
- Add var updateparams to convert the params to a string. Notice that this method uses the parameter '&updatesjson=' to exchange data to/from the Google sheet. When sending data in this manner, the data has to be a string, so we also use the function JSON.stringify(<json variable>) to convert it.
- Run the update – perform an http.put() and eval the results.
Tip |
---|
The column name on a Google sheet must match the control name. The matching is case-insensitive and any spaces in the column name are ignored. A control named "FirstName" matches a column header "first name." However, references to Google Sheet columns in your rule must be lower case and cannot contain spaces. The correct reference for this example is "firstname." |
Note |
---|
Reserved characters in a URL need to be encoded. The example above uses the encodeURIComponent function in JavaScript for every parameter value and invoke the http function with the extra encode parameter set to false. |
Info | ||
---|---|---|
If your rules were developed with a Google Connector prior to v3.0.5, they used the parameter '&updates=' followed by the concatenated column names and control values, such as:
This method is still supported, however it is no longer best practice. When using this method with text or textarea controls, you will find that if the user enters characters such as a comma or equals sign, the rule will encounter an error. Consider using the '&updatesjson=' method described above for the most reliable behavior. |
Step 3: Try it yourself using the sample form
...