Parse.Cloud.afterSave("StatusTable", function(request) {
var deviceName = request.object.get("deviceName");
var lastSeen = request.object.get("entryTime");
var sectionName = request.object.get("sectionName");
var LastSeen = Parse.Object.extend("LastSeen");
var query = new Parse.Query(LastSeen);
query.equalTo("deviceName", deviceName);
query.first().then(function(result) {
result.put("lastSeen", lastSeen);
result.put("sectionName", sectionName);
result.save();
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
);
I have two tables in parse. StatusTable
and LastSeen
table.I need to write a trigger which updates lastSeen
and sectionName
columns of LastSeen
table when a successful insert has occurred in StatusTable
corresponding to the deviceName
.This code is not working.
StatusTable
LastSeenTable
From the Object
documentation: https://parse.com/docs/js/api/classes/Parse.Object.html
There is no put()
method. Try using set()
instead:
query.first().then(function(result) {
result.set("lastSeen", lastSeen);
result.set("sectionName", sectionName);
result.save();
});
Also, are you sure you want your query to use first
instead of find
? Just to ensure that you are always updating the object that you want.