- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从昨天开始,我们在将 REST API (urlfetch) 制作到 Zendesk 中时开始在 Google 电子表格中遇到错误。我们已经使用了 1.5 年,并没有遇到任何问题。它给出的错误是通用的——“遇到错误:很抱歉,发生服务器错误。请稍等一下,然后重试。”错误的屏幕截图 - http://support.prontomarketing.com/attachments/token/j1bjrnw1cpfu4tu/?name=2012-06-27_08-56-19.jpg
Google Apps Script Spreadsheet Services API 最近有什么变化吗?
有没有人有什么想法?
这是我们的脚本:(注意* zendesk 的 url 和 token 已被删除)
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Create Tickets", functionName: "oneToMany"},{name: "Reset Form", functionName: "resetForm"} ];
ss.addMenu("Actions", menuEntries);
}
function resetForm(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var currentIndex = doc.getActiveSelection().getRowIndex();
var totalRow = findThelastRow('a',0);
for (var count=2;count<totalRow;count++)
{
doc.getSheets()[0].getRange('a'+count).clear({contentsOnly:true});
doc.getSheets()[0].getRange('h'+count).clear({contentsOnly:true});
doc.getSheets()[0].getRange('h'+count).setBackgroundColor('#ffffff');
doc.getSheets()[0].getRange('i'+count).clear({contentsOnly:true});
doc.getSheets()[0].getRange('i'+count).setBackgroundColor('#ffffff');
//doc.getSheets()[0].getRange('c'+count).setValue(clearA(doc.getSheets()[0].getRange('c'+count).getValue()));
}
}
function continueRest(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Please Input Your Zendesk Username');
app.setHeight('75');
app.setWidth('400');
// Create a grid with 3 text boxes and corresponding labels
var grid = app.createGrid(1, 2);
// Text entered in the text box is passed in to userName
grid.setWidget(0, 0, app.createLabel('Username:'));
var inputTextBox1 = app.createTextBox().setName('username');
inputTextBox1.setWidth('300px');
grid.setWidget(0, 1,inputTextBox1 );
// Create a vertical panel..
var panel = app.createVerticalPanel();
// ...and add the grid to the panel
panel.add(grid);
// Create a button and click handler; pass in the grid object as a callback element and the handler as a click handler
// Identify the function b as the server click handler
var button = app.createButton('submit').setId('button');
var handler = app.createServerClickHandler('continueSentTheRest');
handler.addCallbackElement(grid);
button.addClickHandler(app.createServerClickHandler('pauseUI'));
button.addClickHandler(handler);
//button.setStyleAttribute('display', 'none');
// Add the button to the panel and the panel to the application, then display the application app in the Spreadsheet doc
panel.add(button);
app.add(panel);
doc.show(app);
}
function oneToMany(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Please Input Your Zendesk Username');
app.setHeight('75');
app.setWidth('400');
// Create a grid with 3 text boxes and corresponding labels
var grid = app.createGrid(1, 2);
// Text entered in the text box is passed in to userName
grid.setWidget(0, 0, app.createLabel('Username:'));
var inputTextBox1 = app.createTextBox().setName('username');
inputTextBox1.setWidth('300px');
grid.setWidget(0, 1,inputTextBox1 );
// Create a vertical panel..
var panel = app.createVerticalPanel();
// ...and add the grid to the panel
panel.add(grid);
// Create a button and click handler; pass in the grid object as a callback element and the handler as a click handler
// Identify the function b as the server click handler
var button = app.createButton('submit').setId('button');
var handler = app.createServerClickHandler('authHandler');
handler.addCallbackElement(grid);
button.addClickHandler(app.createServerClickHandler('pauseUI'));
button.addClickHandler(app.createServerClickHandler('mapValue'));
button.addClickHandler(handler);
//button.setStyleAttribute('display', 'none');
// Add the button to the panel and the panel to the application, then display the application app in the Spreadsheet doc
panel.add(button);
app.add(panel);
doc.show(app);
}
function pauseUI(e) {
var app = UiApp.getActiveApplication();
// try 'pausing' the app while we process the info
app.setTitle('Please wait...');
app.getElementById("button").setEnabled(false);
return app;
}
var table = SpreadsheetApp.getActive().getSheets()[1].getDataRange().getValues();
function selectByIndex( index ) {
Logger.log(table);
for( var i in table )
if( table[i][0] == index )
return table[i];
return null; //or throw exception
}
function mapValue(){
//Get the key value sheet.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('on the loop');
if (sheet != null) {
for (var i in table){
var groupKey =table[i][0];
var groupValue = table[i][1];
//Logger.log(groupKey+' '+groupValue);
if(groupKey!=''&&groupValue!='')
ScriptProperties.setProperty(groupKey,groupValue.toString());
var assigneeKey = table[i][2];
var assigneeValue = table[i][3];
if(assigneeKey!=''&&assigneeValue!='')
ScriptProperties.setProperty(assigneeKey,assigneeValue.toString());
}
//Priority
ScriptProperties.setProperty('P: Low','1');
ScriptProperties.setProperty('P: Normal','2');
ScriptProperties.setProperty('P: High','3');
ScriptProperties.setProperty('P: Urgent','4');
//Browser.msgBox(ScriptProperties.getProperty('Development'));
}
else
{
Browser.msgBox('There is no sheet contain id for the assignee and group.');
}
//Browser.msgBox(ScriptProperties.getProperty('P: Urgent'));
}
function createPayLoad(count){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var requester = doc.getSheets()[0].getRange('a'+count).getValue();
var ticketTitle = doc.getSheets()[0].getRange('b'+count).getValue().toString().replace('&','&');
var ticketComment = doc.getSheets()[0].getRange('c'+count).getValue().toString().replace('&','&');
ticketComment = replaceBR(ticketComment);
ticketComment = replaceA(ticketComment);
var assignee = ScriptProperties.getProperty(doc.getSheets()[0].getRange('d'+count).getValue());
var group = ScriptProperties.getProperty(doc.getSheets()[0].getRange('e'+count).getValue());
Logger.log(doc.getSheets()[0].getRange('f'+count).getValue());
var priority = ScriptProperties.getProperty('P: '+doc.getSheets()[0].getRange('f'+count).getValue().trim());
var tags = 'internal '+doc.getSheets()[0].getRange('g'+count).getValue();
var payLoad = '\n';
payLoad += '<ticket>'+'\n';
payLoad += '<requester-email>'+requester+'</requester-email>'+'\n';
payLoad += '<subject>'+ticketTitle+'</subject>'+'\n';
payLoad += '<description>'+ticketComment+'</description>'+'\n';
payLoad += '<assignee-id>'+assignee+'</assignee-id>'+'\n';
payLoad += '<group-id>'+group+'</group-id>'+'\n';
payLoad += '<priority-id>'+priority+'</priority-id>'+'\n';
payLoad += '<set-tags>'+tags+'</set-tags>'+'\n';
payLoad += '</ticket>';
//Browser.msgBox(payLoad)
return payLoad;
}
function findThelastRow(column,index){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = doc.getLastRow();
for(var i=2;i<=lastRow+1;i++)
{
if(doc.getSheets()[index].getRange(column+i).getValue()=="")
{
return i;
break;
}
}
return 0;
}
function authHandler(e){
if(e.parameter.username=="")
{
Browser.msgBox('Username is required!');
return;
}
var app = UiApp.getActiveApplication();
var doc = SpreadsheetApp.getActiveSpreadsheet();
var currentIndex = doc.getActiveSelection().getRowIndex();
var username = e.parameter.username;
var encode = Utilities.base64Encode(username+'/token:SECRET);
var totalRow = findThelastRow('a',0);
for (var count=2;count<totalRow;count++)
{
if(doc.getSheets()[0].getRange('a'+count).getValue()=='')
{
Browser.msgBox('Requester is required!');
return;
}
var isCreate = doc.getSheets()[0].getRange('i'+count).getValue();
var isNormalUpdate = false;
if(isCreate=='')
{
var payLoad = createPayLoad(count);
var options =
{
"method" : "post",
"headers" : {"Content-type":"application/xml","Authorization": "Basic "+encode},
"payload" : payLoad
};
var result = UrlFetchApp.fetch("http://SECRET/tickets.xml",options);
if(result.getResponseCode()==201) //This means success.
{
var mytool_array=result.getHeaders().toSource().split(",");
Logger.log(mytool_array);
//var ticketNumber=mytool_array[2].split("Location:");
var ticketNumber=result.getHeaders().toSource().split("Location:");
Logger.log(ticketNumber);
var valueTicket=ticketNumber[1].split('.xml')[0].split('tickets/')[1];
doc.getSheets()[0].getRange('h'+count).setValue('=hyperlink("http://SECRET/tickets/'+valueTicket+'";"'+valueTicket+'")');
doc.getSheets()[0].getRange('h'+count).setBackgroundColor('#1BE039');
doc.getSheets()[0].getRange('i'+count).setValue('OK');
doc.getSheets()[0].getRange('i'+count).setBackgroundColor('#1BE039');
}
else
{
doc.getSheets()[0].getRange('i'+count).setValue('FAIL');
break;
return;
}
}
}
// Clean up - get the UiApp object, close it, and return
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}
function continueSentTheRest(e){
var app = UiApp.getActiveApplication();
var doc = SpreadsheetApp.getActiveSpreadsheet();
var indexOfA = findThelastRow('h',0);
if(doc.getSheets()[0].getRange('a'+indexOfA).getValue()=="")
{
Browser.msgBox('Requester is required!');
doc.getSheets()[0].setActiveSelection('a'+indexOfA);
return;
}
var username = e.parameter.username;
username += ':'+e.parameter.password;
var encode = Utilities.base64Encode(username);
var totalRow = findThelastRow('a',0);
for (var count=indexOfA;count<totalRow;count++)
{
var payLoad = createPayLoad(count);
var options =
{
"method" : "post",
"headers" : {"Content-type":"application/xml","Authorization": "Basic "+encode},
"payload" : payLoad
};
var result = UrlFetchApp.fetch("http://SECRET/tickets.xml",options);
if(result.getResponseCode()==201) //This means success.
{
var mytool_array=result.getHeaders().toSource().split(",");
var ticketNumber=mytool_array[2].split("Location:");
var valueTicket=ticketNumber[1].split('.xml')[0].split('tickets/')[1];
doc.getSheets()[0].getRange('h'+count).setValue('=hyperlink("http://SECRET/tickets/'+valueTicket+'";"'+valueTicket+'")');
doc.getSheets()[0].getRange('h'+count).setBackgroundColor('#1BE039');
doc.getSheets()[0].getRange('i'+count).setValue('OK');
doc.getSheets()[0].getRange('i'+count).setBackgroundColor('#1BE039');
}
else
{
doc.getSheets()[0].getRange('i'+count).setValue('FAIL');
break;
return;
}
}
// Clean up - get the UiApp object, close it, and return
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
var temp = this;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
function replaceBR(input)
{
return input.ReplaceAll('<br>','
');
}
function replaceA(input)
{
input = input.ReplaceAll('<a>',' ');
input = input.ReplaceAll('</a>',' ');
return input;
}
function clearA(input)
{
return input.replace(/<a>.*<\/a>/g,'<a></a>');
}
最佳答案
您原来的 findThelastRow(column,index)
函数有一个从事件工作表的 0 到 lastRow 的循环,但随后使用(最终)寻址其他工作表中的范围这个循环值。其他工作表中可能不存在该行索引。
多年来,您可能对此没有任何问题,具体取决于不同工作表中存在多少行,但也许现在这种情况正在发生......
为了防止这种风险,我建议在 findThelastRow
函数中尝试这样做:
function findThelastRow(column,index){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = doc.getSheets()[index].getLastRow();// check last row on the appropriate sheet
for(var i=2;i<=lastRow+1;i++)
{
if(doc.getSheets()[index].getRange(column+i).getValue()=="")
{
return i;
break;
}
}
return 0;
}
编辑:这个函数可以是 written more efficiently不在相当慢的循环中使用 getValue()
...这是一个使用数组的兼容版本:(你可以替换它而不做任何改变)
function findThelastRow(column,index){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = doc.getSheets()[index].getLastRow()+1;// check last row on the appropriate sheet
var coldata = doc.getSheets()[index].getRange(column+2+':'+column+lastRow).getValues();// I begin on Row 2 just as you did
for(i=coldata.length-1;i>=0;i--){
if(coldata[i][0]!=''){return i+2;break}
}
return 0;
}
关于javascript - 电子表格中的 Google Apps 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11218440/
这里的这个问题对 updating Google Sheets charts linked to Google slides 有一个简洁的解决方案. function onOpen() { var
我正在尝试将 Google 表单添加到 Google 类作业中,但似乎不可能。 首先,它在这里 ( https://developers.google.com/classroom/reference/
出于某种原因,无论我做什么以及我如何尝试,这个日期格式化程序都不起作用。工具提示仍然显示错误的格式。你可以试试代码here . 在代码中我必须注释掉 formatter.format(dataTabl
我目前正在使用访问 token 和刷新 token 从 Google Analytics Reporting API (v4) 中提取数据。当我致力于自动从 Google Analytics 中提取数
我已在 Google 云端硬盘中创建了一个文件夹,例如测试一下,放入3个文件 a.jpg, b.jpg, c.jpg 我希望在同一帐户下的 Google 电子表格中访问文件,例如生成图像文件的链接,可
电子表格 A 是欢迎新移民来到我们小镇的团队的主数据源。它里面有大量非常敏感的数据,不能公开,哪怕是一点点。 (我们谈论的是 child 的姓名和出生日期以及他们在哪里上学……保证电子表格 A 的安全
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
尝试检索存储在 google firebase 中名为条目的节点下的表单条目,并使用谷歌工作表中的脚本编辑器附加到谷歌工作表。 我已将 FirebaseApp 库添加到谷歌表脚本编辑器。然后我的代码看
是否可以将我的 Web 应用程序的登录限制为仅限 google 组中的帐户? 我不希望每个人都可以使用他们的私有(private) gmail 登录,而只能使用我的 google 组中的用户。 最佳答
我们想使用 Google 自定义搜索实现 Google 附加链接搜索框。在谷歌 documentation , 我发现我们需要包含以下代码来启用附加链接搜索框 { "@context"
我想将特定搜索词的 Google 趋势图表添加到我的 Google Data Studio 报告中,但趋势不是数据源列表中的选项。我也找不到嵌入 JavaScript 的选项。是否可以将趋势图表添加到
是否可以将文件从 Google Drive 复制到 Google Cloud Storage?我想它会非常快,因为两者都在类似的存储系统上。 我还没有看到有关无缝执行此操作的任何方法的任何信息,而无需
之间有什么区别 ga('send', 'pageview', { 'dimension1': 'data goes here' }); 和 ga('set', 'dimension1', 'da
我正在尝试记录每个博客站点作者的点击率。 ga('send', 'pageview'); (in the header with the ga code to track each page) ga(
我设置了 Google Tag Manager 和 2 个数据层变量:一个用于跟踪用户 ID,传递给 Google Analytics 以同步用户 session ,另一个用于跟踪访问者类型。 在使用
我在我们的网站上遇到多个职位发布的问题。 我们在加拿大多个地点提供工作机会。所有职位页面都包含一个“LD+JSON ”职位发布的结构化数据,基于 Google 的职位发布文档: https://dev
公司未使用 Google 套件,使用个人(消费者)帐户(甚至是 Google 帐户)违反公司政策。 需要访问 Google Analytics - 没有 Google 帐户是否可能? 谢谢 最佳答案
我想分析人们使用哪些搜索关键字在 Play 商店中找到我的应用。 那可能吗?我怎么能这样做? 最佳答案 自 2013 年 10 月起,您可以关联您的 Google Analytics(分析)和 Goo
Google Now 和 Google Keep 中基于时间和位置的提醒与 Google Calendar 事件提醒不同。是否有公共(public) API 可以访问 Now 和 Keep 中的这些事
我是一名优秀的程序员,十分优秀!