【发布时间】:2018-08-10 16:56:28
【问题描述】:
使用 Google 表格,其中每一行都包含一个 ID 和一个 picklist 值。示例:Google Sheet。
我要做的是在有人编辑 picklist 单元格时运行自定义函数。该函数接受两个参数,来自同一行的 ID 和选项列表单元格的值,然后执行 HTTP POST 请求以更新我们 CRM 中的记录。
//When STAGE cell on Google Sheet is updated, run this function:
function updateProjectStage(status, id) {
var baseURL = 'https://crm.zoho.com/crm/private/json/Potentials/updateRecords?authtoken=xxx&scope=crmapi&id=', // see docs https://www.zoho.com/crm/help/api/updaterecords.html
recordID = id, // building id from A column
stage = '<Potentials><row no="1"><FL val="Stage">' + status + '</FL></row></Potentials>'; // status from B column
var postURL = baseURL + recordID + '&xmlData=' + stage;
Logger.log(postURL);
var response = UrlFetchApp.fetch(postURL); // update record in crm
var sanitizedResponse = JSON.parse(response.getContentText()); // get confirmation/failure
Logger.log(sanitizedResponse);
}
我不知道如何为这种选择列表类型的单元格运行该函数 - 我不能像以前那样在单元格中输入=updateProjectStage(status, id),因为它会出错。
例如:Error Message。
这可能吗?
【问题讨论】:
-
您的 Go 代码似乎没有任何问题,只是如何从 Google 表格进行 API 调用,所以这可能更适合 Super User。
-
嗯,这必须用 golang 编写,所以我不知道你为什么这么说 - 这正是我遇到的问题。我什至不知道该写什么;当然必须有一些辅助函数来处理事件 - 但它们可以在 Google 表格自定义函数脚本中使用吗?
-
Google 表格脚本在浏览器中运行,Go 没有。我以为您在某种服务中运行此 Go 代码,也许我不太理解您的问题。
标签: google-apps-script google-sheets google-sheets-api