我想创建一个触发器来更新另一条记录,其中特定字段包含google app maker sql中的字符串。怎么做?请帮助我。
这是我的第一个表“ User”(Id,Code,Fname,Lname),当我在其中插入某些内容时,我想更新另一个表“ History”(Id,User,dateUpdate, Counter < / em>)。这是我的“用户”事件中“ onAfterCreate”事件的脚本。
var query = app.models.History.newQuery();
query.filters.User._equals = Session.getActiveUser().getEmail().toString();
var records = query.run();
//console.log("Found " + records.length + " Users.");
if(records.length > 0){
var nilBaru = Math.round(records[0].Count)+1;
//I want to get "History" field that contains specific string and if exist i want to update it's records.
}else{
var sejarah = app.models.History.newRecord();
var userEmail = Session.getActiveUser().getEmail().toString();
var update = new Date();
sejarah.User = userEmail;
sejarah.Update = update;
sejarah.Count = 1;
app.saveRecords([sejarah]);
}
谢谢..
答案 0 :(得分:0)
哦,我自己解决。.哈哈哈
var query = app.models.History.newQuery();
query.filters.User._equals = Session.getActiveUser().getEmail().toString();
var records = query.run();
var id = records[0]._key;
//console.log("Found " + records.length + " Users.");
if(records.length > 0){
var nilBaru = Math.round(records[0].Count)+1;
var record = app.models.History.getRecord(id);
record.Count = nilBaru;
app.saveRecords([record]);
}else{
var sejarah = app.models.History.newRecord();
var userEmail = Session.getActiveUser().getEmail().toString();
var update = new Date();
sejarah.User = userEmail;
sejarah.Update = update;
sejarah.Count = 1;
app.saveRecords([sejarah]);
}