0

I'm attempting to filter some results using azure mobile service scripts but i'm getting this error in the log.The parameters I pass to this function are also shown.

ERROR Error in script '/table/Restaurant.read.js'. Error: Invalid callback options passed to 'query'. Callback options must be an object with at least one 'success' or 'error' property of type 'function' or a systemProperties property of type 'Array'. [external code] at read (:7:11) at :1:6 [external code]

Here's my code

function read(query, user, request) {
  var location=request.parameters.Location;
  var category=request.parameters.Category;
  console.log("location is"+location);
   console.log("category is"+category);
   var sql="SELECT * from restaurant where Location=? AND Category=?";
   mssql.query(sql,[location],[category],{success:function(results){request.respond(statusCodes.Ok,results);}});

 } 

1 Answer 1

1

The parameters to the query need to be passed as a single array, instead of an array per parameter. If you change your query from

mssql.query(sql, [location], [category], {
    success: function(results) { request.respond(statusCodes.Ok, results); }
});

to

mssql.query(sql, [location, category], {
    success: function(results) { request.respond(statusCodes.OK, results); }
});

It should work. As a side note, you should use statusCodes.OK instead of statusCodes.Ok ("OK" all in caps).

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.