Search code examples
parse-platform

Run parse aftersave cloud code only on certain attributes


I set up the parse cloud code and its working great. I am looking for a way to run aftersave cloud code only if certain attributes are modified. Is it possible ?


Solution

  • I am not sure what you want to do exactly, but you may use dirty or dirtyKeys to check if your attributes are modified in beforeSave.

    In afterSave existed can be useful too to check if the object is just created or already existed.

    Example for dirty:

    Parse.Cloud.beforeSave("Location", function(request, response) {
      var location = request.object;
    
      if (location.dirty("photo")) {
        // photo is modified
        // do something (like resizing the photo as thumbnail)
      } 
    
      response.success();
      return;
    });