Javascript 谷歌应用程序脚本没有为每个人加载功能,只有我
当打开我的事件谷歌工作表时,我的onSheetOpen/showSidebar不适用于除我之外的任何人。我已经为自己设置了启动onSheetOpen和showSidebar的触发器,但这对打开电子表格的任何人都不起作用。有人能帮我弄清楚为什么会这样吗?下面是我正在使用的代码Javascript 谷歌应用程序脚本没有为每个人加载功能,只有我,javascript,google-apps-script,google-sheets,triggers,Javascript,Google Apps Script,Google Sheets,Triggers,当打开我的事件谷歌工作表时,我的onSheetOpen/showSidebar不适用于除我之外的任何人。我已经为自己设置了启动onSheetOpen和showSidebar的触发器,但这对打开电子表格的任何人都不起作用。有人能帮我弄清楚为什么会这样吗?下面是我正在使用的代码 /** * Set up custom sidebar. * TRIGGER: spreadsheet event 'on open' */ function onSheetOpen() { var ui = S
/**
* Set up custom sidebar.
* TRIGGER: spreadsheet event 'on open'
*/
function onSheetOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Actions')
.addItem("Register interest in current opportunity", 'registerInterest')
.addItem("Show sidebar", 'showSidebar')
.addToUi();
showSidebar();
}
/**
* Renders the sidebar
* TRIGGER: spreadsheet event 'on open' & custom menu option
*/
function showSidebar() {
try {
var htmlOutput = HtmlService.createHtmlOutputFromFile('sidebar');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
} catch(e) {
// Just ignore - means user doesn't have edit access to sheet
}
}
/**
* Main function. Grabs the required data from the currently-selected row, registers interest
* in that data in a separate sheet, and sends a confirmation email to the user.
*/
function registerInterest() {
//var spreadsheet = SpreadsheetApp.getActive();
// These are the attributes we capture and store in the 'interest' sheet
var who = Session.getActiveUser().getEmail();
var when = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss');
var data = getRowOfInterest(SpreadsheetApp.getActiveSheet());
var id = Utilities.getUuid();
Logger.log(id)
if(data.what && data.what.length > 0) {
// Get the Google Sheets ID of the target 'interest' sheet
var id = getConfigValue("InterestSheet");
if(id) {
// Now try and open that sheet for updating
var ss = SpreadsheetApp.openById(id);
if(ss) {
var sheet = ss.getSheetByName('Interest');
if(sheet) {
// All good; log interest. First, create the new row of data for the target sheet
sheet.appendRow([ when, who, data.what, data.subject, data.location, data.industry, data.capabilities ]);
// Second, grab our 'template' email from config & use that to send a confirmation
// email to the person registering their interest
var body = getConfigValue('InterestEmail');
MailApp.sendEmail(who, getConfigValue('InterestSubject'), null, { noReply: true, htmlBody: body });
} else {
throw Error('can\'t open the \'Interest expressed\' sheet (or it doesn\'t exist)');
}
} else {
throw Error('can\'t open the \'Interest expressed\' sheet');
}
} else {
throw Error('\'Interest expressed\' sheet not specified');
}
}
}
/**
* Utility to derive the required data for registering interest.
* Called from the registerInterest() function
*/
function getRowOfInterest(sheet) {
var result = {};
var row = sheet.getActiveRange().getRow(); // Get the currently-selected row index
var fullRange = sheet.getRange(row, 1, 1, sheet.getLastColumn()); // Get the entire row of data
//var fullRange = sheet.getRange(row, 1, 1, 9);
Logger.log(fullRange.getValues())
var data = fullRange.getValues();
if(data[0] && data[0].length > 0) {
for(var n = 0; n < data[0].length; n++) {
// Populate specific attributes in the 'result' object - tailor this as you see fit
if(n==0) result.subject = data[0][n];
if(n==6) result.what = data[0][n] + ' ';
//if(n==5 || n==7) result.what += data[0][n] + ' ';
if(n==7) result.location = data[0][n];
if(n==11) result.industry = data[0][n];
if(n==12) result.capabilities = data[0][n];
}
result.what += '(' + sheet.getName() + ')';
result.industry;
result.capabilities;
return result;
}
}
function getSomeRange(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var row = sheet.getActiveRange().getRow(); // Get the currently-selected row index
var myRange = sheet.getRange(row, 1, 1, sheet.getLastColumn());
//Logger.log("Number of rows in range is "+myRange.getNumRows()+ " Number of columns in range is "+ myRange.getNumColumns());
}
/**
* Utility to pull specified data from a config sheet. This assumes that a sheet called 'Config'
* is populated thus:
* Column contains a load of 'key' and column 2 contains the corresponding 'values'
* Called from registerInterest() function
*/
function getConfigValue(key) {
var sheet = SpreadsheetApp.getActive().getSheetByName('Config');
var result;
if(sheet) {
// Scan column 1 for key and return value in column 2
var data = sheet.getDataRange().getValues();
for(var n = 0; n < data.length; ++n) {
if(data[n][0].toString().match(key)) result = data[n][1];
}
}
return result;
}
function hideExpiredEvents() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Events');
var exsh=ss.getSheetByName('Expired Events');
var sr=2;
var rg=sh.getRange(sr,1,sh.getLastRow()-sr+1,sh.getLastColumn());
var vA=rg.getValues();
Logger.log(vA);
var dt=new Date();
var d=0;//deleted row counter
var today=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate(0)).valueOf();
for(var i=0;i<vA.length;i++) {
if(new Date(vA[i][3]).valueOf()<today) {
exsh.appendRow(vA[i]);//move to bottom of expired events
sh.deleteRow(i+sr-d++);//increment deleted row counter
}
}
}
/**
*设置自定义侧边栏。
*触发器:电子表格事件“打开”
*/
函数onSheetOpen(){
var ui=SpreadsheetApp.getUi();
ui.createMenu(“操作”)
.addItem(“注册当前opportunity中的权益”,“注册权益”)
.addItem(“显示侧栏”,“显示侧栏”)
.addToUi();
showSidebar();
}
/**
*渲染侧边栏
*触发器:电子表格事件“打开时”&自定义菜单选项
*/
函数showSidebar(){
试一试{
var htmlOutput=HtmlService.createHtmlOutputFromFile('sidebar');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
}捕获(e){
//忽略-表示用户没有对工作表的编辑权限
}
}
/**
*主要功能。从当前选定的行中获取所需数据,并注册兴趣
*在该表中,数据将显示在单独的表格中,并向用户发送确认电子邮件。
*/
函数registerInterest(){
//var电子表格=SpreadsheetApp.getActive();
//这些是我们捕获并存储在“兴趣”表中的属性
var who=Session.getActiveUser().getEmail();
var when=Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'yyyy-MM-dd HH:MM:ss');
var data=getRowOfInterest(SpreadsheetApp.getActiveSheet());
var id=Utilities.getUuid();
Logger.log(id)
if(data.what&&data.what.length>0){
//获取目标“兴趣”表的Google Sheets ID
var id=getConfigValue(“利息表”);
如果(id){
//现在尝试打开该工作表进行更新
var ss=电子表格应用程序openById(id);
if(ss){
var sheet=ss.getSheetByName(“利息”);
若有(第页){
//一切正常;记录兴趣。首先,为目标工作表创建新行数据
sheet.appendRow([when,who,data.what,data.subject,data.location,data.industry,data.capabilities]);
//第二,从配置中抓取我们的“模板”电子邮件并使用它发送确认
//向登记其利益的人发送电子邮件
var body=getConfigValue('InterestEmail');
sendmail(who,getConfigValue('interestObject'),null,{noReply:true,htmlBody:body});
}否则{
抛出错误('无法打开'利益表达'表(或它不存在)');
}
}否则{
抛出错误('无法打开'兴趣表达'表');
}
}否则{
抛出错误(“\'兴趣表达\未指定工作表”);
}
}
}
/**
*用于获取注册兴趣所需数据的实用程序。
*从registerInterest()函数调用
*/
函数getRowOfInterest(表){
var result={};
var row=sheet.getActiveRange().getRow();//获取当前选定的行索引
var fullRange=sheet.getRange(row,1,1,sheet.getLastColumn());//获取整行数据
//var fullRange=sheet.getRange(第1、1、9行);
Logger.log(fullRange.getValues())
var data=fullRange.getValues();
if(数据[0]&数据[0]。长度>0){
对于(var n=0;n对于(var i=0;i不幸的是,您遇到的问题可能是一个bug
在这种情况下,您可以通过单击★在问题编号旁边发表评论,并说明您受到问题的影响。不幸的是,您遇到的问题可能是一个bug
在这种情况下,您可以通过单击★在问题编号旁边发表评论,并说明您受到问题的影响。Hello@Mi