7

I know in the iOS sdk I can do it like this

[PFCloud callFunctionInBackground:@"email" withParameters:@{@"param1": @"quantity1, @"param2": @"quantity2} block:^(NSString *result, NSError *error) {
    if (error) {
        //error
    } else {
        // make sure the set the email sent flag on the object
        NSLog(@"result :%@", result);
    }
}];

but how would I do this with a Javascript function

Talha Awan
  • 4,573
  • 4
  • 25
  • 40
user379468
  • 3,989
  • 10
  • 50
  • 68

2 Answers2

13

Parse.Cloud implements run()...

Parse.Cloud.run("email", { param1:"quantity1", param2:"quantity2" }).then(function(result) {
    // make sure the set the email sent flag on the object
    console.log("result :" + JSON.stringify(result))
}, function(error) {
    // error
});
Talha Awan
  • 4,573
  • 4
  • 25
  • 40
danh
  • 62,181
  • 10
  • 95
  • 136
2
Parse.Cloud.define("email", function(request, response) {
  var param1 = request.params.param1; 
  var param2 = request.params.param2;
  response.success("success"); //your response
  }, function(error) {
    // Make sure to catch any errors, otherwise you may see a "success/error not called" error in Cloud Code.
    response.error("Could not retrieve Posts, error " + error.code + ": " + error.message);
  }); 

Working perfect with below code

NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:@"A",@"param1",@"B",@"param2", nil];
    [PFCloud callFunctionInBackground:@"email" withParameters:param block:^(id object, NSError *error)
    {

    }];
Muhammad Awais
  • 340
  • 3
  • 15