0

I try to update a value in my Parse.com Core, but it simply does not work. I have the "objectID" of the item that i want to update

 Parse.initialize("xxxx", "xxxx");

    var PP = Parse.Object.extend("PP");
    var PP = new PP();

    var query = new Parse.Query(PP);
                        query.equalTo("objectId", "3Enwfu0QPQ");
                        query.first({
                            success: function (PP) {
                                PP.save(null, {
                                    success: function (PP) {

                                        PP.set("free", "100");


                                        PP.save();
                                    }
                                });

                            }
                        });

i want to set the value of "free" for object "3Enwfu0QpQ" to 100, but it does not work.

enter image description here

1 Answer 1

2

There's several issues with your code:

1.

var PP = Parse.Object.extend("PP");
var PP = new PP();

According to your screenshot, the Class is named "P", not "PP". You are also overriding the PP object.

2.

var query = new Parse.Query(PP);
query.equalTo("objectId", "3Enwfu0QPQ");
query.first({[...]});

query is invalide because PP is no longer the PP object. You should also use query.get instead of equalTo.

3.

PP.save(null, {
  success: function (PP) {
    PP.set("free", "100");
    PP.save();
  }
});

You are saving an empty object then editing this same object, then you update it again.

Your code should look like this (untested).

Parse.initialize("xxxx", "xxxx");

var P = Parse.Object.extend("P");

var query = new Parse.Query(P);
query.get('3Enwfu0QPQ', { // we get the object
  success: function (instance) {
    instance.set("free", "100"); // We update the returned object
    instance.save(); // we save it
  }
});

You can also save a request by doing so:

Parse.initialize("xxxx", "xxxx");

var P = Parse.Object.extend("P");

var instance = new P();
instance.id = '3Enwfu0QPQ';
instance.set("free", "100");
instance.save();
Sign up to request clarification or add additional context in comments.

2 Comments

i just did try it but no success, it "joins" the success function but does not update the value for me seem to be a problem that it is a "number" and not a string thats why the "" should be removed
Did you have it working? I edited my answer to add a much simpler code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.