0

Inside a app, users will upload slot results with period name to the Parse Database. However, before upload, it would be much preferred if beforesave, checked whether the period ref is already there, if the same period ref is existing in the DB, the slot result would not be uploaded.

Cloud.beforesave

Parse.Cloud.beforeSave("check_duplicate", function(request, response) 
{
    var DB = Parse.Object.extend("Record_db"); 
    var query = new Parse.Query(DB);
        query.equalTo("period_ref", request.object.get("period_ref"));
        query.first
        ({
      success: function(object) 
    {
            if (object) 
        {
                response.error("A Period with this ref already exists.");
            } 
        else 
        {
                response.success();
            }
      },
      error: function(error) 
    {
        response.error("Could not validate uniqueness for this period ref object.");
        }
    });  
});

Android code:

ParseCloud.callFunctionInBackground("check_duplicate", new HashMap<String, Object>(), new FunctionCallback<String>() {
      public void done(String result, ParseException e) 
      {
        if (e == null) 
        {
            Utilities.custom_toast(CurrentResult.this, "cloud success" + result, "gone!", "short");
        }
        else
        {
            Utilities.custom_toast(CurrentResult.this, "cloud error" + e, "gone!", "short");
        }
      }
    });

Question:

There is no clear example for such common situation. I would like to ask for example, now the user would like to upload slot ref 001/2015 results. All info are already available at device, how could I pass this period reference 001/2015 to the cloud code for checking whether it is already existing in the Cloud DB uploading and saving to the Cloud DB?

Thanks a lot!

2
  • "period_ref" is keyOfType=String "001/2015" is a value object. Plug them into your Hashmap before making the android call. Commented Mar 12, 2015 at 18:10
  • Could you please kindly tell how could that be done? Commented Mar 13, 2015 at 1:30

1 Answer 1

2

your first line of Android...

ParseCloud.callFunctionInBackground("check_duplicate", new HashMap(), new FunctionCallback() {

becomes

ParseCloud.callFunctionInBackground("check_duplicate", 
new HashMap<String, String>{"period_ref":"001/2015"};, 
new FunctionCallback<String>() {
Sign up to request clarification or add additional context in comments.

Comments

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.