pearmak
pearmak

Reputation: 5027

Android: How to input values to Parse cloud code, eg beforesave

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!

Upvotes: 0

Views: 757

Answers (1)

Robert Rowntree
Robert Rowntree

Reputation: 6289

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>() {

Upvotes: 2

Related Questions