Google apps script &引用;遇到错误:参数“无效”;in处理函数

Google apps script &引用;遇到错误:参数“无效”;in处理函数,google-apps-script,Google Apps Script,我在处理函数中遇到了这个错误,但我不知道是什么导致了它。我复制了代码并在非处理函数中调试了它,没有出现错误 function _responseToNext(e) { var app = UiApp.getActiveApplication(); app.getElementById('btnPrev').setEnabled(true); var current = parseInt(CacheService.getPublicCache().get('currentItem'

我在处理函数中遇到了这个错误,但我不知道是什么导致了它。我复制了代码并在非处理函数中调试了它,没有出现错误

function _responseToNext(e) {

  var app = UiApp.getActiveApplication();
  app.getElementById('btnPrev').setEnabled(true);

  var current = parseInt(CacheService.getPublicCache().get('currentItem')); 
  var agendaItems = Utilities.jsonParse(CacheService.getPublicCache().get('agenda'));

  agendaItems[current]['notes'] = e.parameter.tAreaNotes;
  agendaItems[current]['status'] = e.parameter.lboxStatus;

  CacheService.getPublicCache().put('agenda', Utilities.jsonStringify(agendaItems));

  current = current + 1;
  CacheService.getPublicCache().put('currentItem', current); 

  fillAgendaDetail(app);

  // only enabled 'Next' if there are more items in the agenda
  if (current < agendaItems.length-1) { 
  app.getElementById('btnNext').setEnabled(true); 
  }

  return app;
}
功能_响应下一步(e){
var app=UiApp.getActiveApplication();
app.getElementById('btnPrev').setEnabled(true);
var current=parseInt(CacheService.getPublicCache().get('currentItem');
var agendaItems=Utilities.jsonParse(CacheService.getPublicCache().get('agenda');
agendaItems[当前]['notes']=e.parameter.tAreaNotes;
agendaItems[当前]['status']=e.parameter.lboxStatus;
CacheService.getPublicCache().put('agenda',Utilities.jsonString(agendaItems));
电流=电流+1;
CacheService.getPublicCache().put('currentItem',current);
fillAgendaDetail(app);
//仅当议程中有更多项目时才启用“下一步”
如果(当前
我想,错误原因是缓存
get
方法在缓存为空的第一次执行期间返回null。
Utilities.jsonParse
抛出异常,缓存在任何情况下都变为空。尝试使用以下修改过的代码

function _responseToNext(e) {

  var app = UiApp.getActiveApplication();
  app.getElementById('btnPrev').setEnabled(true);

  var cachedCurrent = CacheService.getPublicCache().get('currentItem');
  var current;
  if (cachedCurrent == null) {
    current = 0;
  }
  else {
    current = parseInt(cachedCurrent); 
  }
  var cachedAgendaItems = CacheService.getPublicCache().get('agenda');
  var agendaItems;
  if (cachedAgendaItems == null) {
    agendaItems = [][];
  }
  else {
    agendaItems = Utilities.jsonParse();
  }

  agendaItems[current]['notes'] = e.parameter.tAreaNotes;
  agendaItems[current]['status'] = e.parameter.lboxStatus;

  CacheService.getPublicCache().put('agenda', Utilities.jsonStringify(agendaItems));

  current = current + 1;
  CacheService.getPublicCache().put('currentItem', current); 

  fillAgendaDetail(app);

  // only enabled 'Next' if there are more items in the agenda
  if (current < agendaItems.length-1) { 
  app.getElementById('btnNext').setEnabled(true); 
  }

  return app;
}
功能_响应下一步(e){
var app=UiApp.getActiveApplication();
app.getElementById('btnPrev').setEnabled(true);
var cachedCurrent=CacheService.getPublicCache().get('currentItem');
无功电流;
if(cachedCurrent==null){
电流=0;
}
否则{
current=parseInt(cachedCurrent);
}
var cachedAgendaItems=CacheService.getPublicCache().get('agenda');
var agendaItems;
if(cachedAgendaItems==null){
代理项=[]];
}
否则{
agendaItems=Utilities.jsonParse();
}
agendaItems[当前]['notes']=e.parameter.tAreaNotes;
agendaItems[当前]['status']=e.parameter.lboxStatus;
CacheService.getPublicCache().put('agenda',Utilities.jsonString(agendaItems));
电流=电流+1;
CacheService.getPublicCache().put('currentItem',current);
fillAgendaDetail(app);
//仅当议程中有更多项目时才启用“下一步”
如果(当前

另外,请注意,对于脚本的所有用户,公共缓存(
CacheService.getPublicCache()
)是相同的。在您的情况下,这意味着,如果两个用户
user1@example.com
user2@example.com
使用脚本,它们将具有相同的
当前
代理项
变量值,也就是说,这可能是这样一种情况,即
\u responseToNext
处理程序已经在
user1
权限下执行-
当前
变量等于1,在user2执行
\u responseToNext
处理程序之后-
当前
变量等于2,依此类推。如果不需要这种行为,请使用
CacheService.getPrivateCache()

我不确定这是否是实际原因,因为我在调用函数的开头为缓存分配了一个值。但是,我不再看到错误,所以谢谢!