3
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

enter image description here

LastSeenTable

enter image description here

Neeraj
  • 1,769
  • 3
  • 24
  • 41

1 Answers1

2

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.

Ryan Sayles
  • 3,389
  • 11
  • 56
  • 79
  • 1
    I am new to this cloud. Could you please tell me where can I see the output of 'alert' function. In JS we use console.log, do we have anything as such here? – Nidhin David Jan 08 '16 at 16:04