如何在编辑时从 google 驱动器 sheet 获得通知?
How to get notification from google drive sheet on edit?
我想在有人更改 google 驱动器中存储的文档时向第三方应用程序发送通知。
有人可以帮助我如何将脚本与任何文档绑定以及何时有人对该脚本进行更改应该 运行 并向第三方应用程序发送通知。
我已经尝试了下面的代码但是它不起作用。
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedRow = sheet.getActiveRange().getRowIndex();
var editedolumn = sheet.getActiveRange().getColumnIndex();
var values = sheet.getSheetValues(editedRow, editedolumn, 1, 6);
Logger.log(values);
getSession();
}
function getSession(){
var payload =
{
"username" : "username",
"password" : "password",
};
var options =
{
"method" : "post",
"payload" : payload,
"followRedirects" : false
};
var login = UrlFetchApp.fetch("https://abcd.service-now.com/nav_to.do?uri=login.do" , options);
Logger.log(login);
var sessionDetails = login.getAllHeaders()['Set-Cookie'];
Logger.log(sessionDetails);
sendHttpPost(sessionDetails);
}
function sendHttpPost(data) {
var payload = {"category" : "network","short_description" : "Test"};
var headers = {"Cookie" : data}
var url = 'https://abcd.service-now.com/api/now/table/incident';
var options = {'method': 'post','headers': headers,'payload': payload,'json': true};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
当有人更改存储在 google 驱动器
中的文档时,向第三方应用程序发送通知
基于此Google Drive Help Forum, this feature hasn't been added yet. However, you may set notifications in a spreadsheet to find out when there's some modifications done in your spreadsheet. To set notifications in a spreadsheet:
- 打开要设置通知的电子表格。
- 单击“工具”>“通知规则”。
- 在出现的 window 中,select 您想要的时间和频率
接收通知。
- 点击保存。
并且,将脚本与任何文档绑定
您可以在 Scripts Bound to Google Sheets, Docs, or Forms 文档中找到完整的指南。如前所述,
To create a bound script, open a Google Sheets, Docs, or Forms file, then select Tools > Script editor. To reopen the script in the future, do the same thing. Because bound scripts do not appear in Google Drive, that menu is the only way to find or open the script.
我想在有人更改 google 驱动器中存储的文档时向第三方应用程序发送通知。
有人可以帮助我如何将脚本与任何文档绑定以及何时有人对该脚本进行更改应该 运行 并向第三方应用程序发送通知。
我已经尝试了下面的代码但是它不起作用。
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedRow = sheet.getActiveRange().getRowIndex();
var editedolumn = sheet.getActiveRange().getColumnIndex();
var values = sheet.getSheetValues(editedRow, editedolumn, 1, 6);
Logger.log(values);
getSession();
}
function getSession(){
var payload =
{
"username" : "username",
"password" : "password",
};
var options =
{
"method" : "post",
"payload" : payload,
"followRedirects" : false
};
var login = UrlFetchApp.fetch("https://abcd.service-now.com/nav_to.do?uri=login.do" , options);
Logger.log(login);
var sessionDetails = login.getAllHeaders()['Set-Cookie'];
Logger.log(sessionDetails);
sendHttpPost(sessionDetails);
}
function sendHttpPost(data) {
var payload = {"category" : "network","short_description" : "Test"};
var headers = {"Cookie" : data}
var url = 'https://abcd.service-now.com/api/now/table/incident';
var options = {'method': 'post','headers': headers,'payload': payload,'json': true};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
当有人更改存储在 google 驱动器
中的文档时,向第三方应用程序发送通知基于此Google Drive Help Forum, this feature hasn't been added yet. However, you may set notifications in a spreadsheet to find out when there's some modifications done in your spreadsheet. To set notifications in a spreadsheet:
- 打开要设置通知的电子表格。
- 单击“工具”>“通知规则”。
- 在出现的 window 中,select 您想要的时间和频率 接收通知。
- 点击保存。
并且,将脚本与任何文档绑定
您可以在 Scripts Bound to Google Sheets, Docs, or Forms 文档中找到完整的指南。如前所述,
To create a bound script, open a Google Sheets, Docs, or Forms file, then select Tools > Script editor. To reopen the script in the future, do the same thing. Because bound scripts do not appear in Google Drive, that menu is the only way to find or open the script.