我得到我的处理函数这个错误,但我一直不知道是什么导致了它。 我复制的代码,并在非处理函数调试,并没有错误。
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;
}
我想,错误的原因是缓存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;
}
同时,请市民缓存( CacheService.getPublicCache()
是你的脚本的所有用户相同。 在你的情况,这意味着,如果两个用户user1@example.com
和user2@example.com
使用脚本,他们将有相同的current
和agendaItems
当变量的值,也就是说,它可以是一个情况_responseToNext
处理器已经下执行user1
权威机构- current
变量等于1,用户2执行后_responseToNext
处理程序-的current
变量等于2,依此类推。 如果你不需要这样的行为,使用CacheService.getPrivateCache()