2
votes

I can't seem to figure out how to pass parameters to azure mobile services using the html/javascript client.

I want to insert in a table, with parameters.

client = new WindowsAzure.MobileServiceClient('https://<myappid>.azure-mobile.net/', 'APPKEY');
client.getTable('myTable').insert(myJsonObj, { myParam: true });

if my insert code looks like

function insert(item, user, request) {
  if(request.parameters.myparam) {
  // do stuff
  }
}

How do I set the parameters variable in request through the html/javascript mobile client? I've found examples with the WP8 SDK it has a .withparameters function, and this question outlines how to do it for a read, Passing Query Parameters from HTML/JS App to Azure Server Script and then the most promising is http://blogs.msdn.com/b/writingdata_services/archive/2013/01/02/mobile-services-custom-parameters-in-windows-store-apps.aspx but the javascript only applies to the Windows store javascript library.

Thanks!

EDIT: So turns out my code was correct and there was an environment issue not pushing the new JS files #noobMistake

anyway passing parameters on an insert can be done in the Azure mobile services library by passing them in after the initial object.

 client.getTable('myTable').insert(myJsonObj, <PARAMS HERE>);

they will be set to the parameters variable in the request object server side!

1
The WinJS and HTML/JS share the same APIs generally. What you showed should be correct. client.getTable('table').insert(item, { param: value }); Try doing console.log(request.parameters) and seeing what it shows. You may just have a casing issue: .myParam over .myparam - phillipv
@phillipv you're indeed correct. I restarted everything and tried the same code again and it works now...after hours of trying to figure this out. Maybe the JS file was cached in my browser or something. Thanks for the help! - jonfriesen

1 Answers

1
votes

So turns out my code was correct and there was an environment issue not pushing the new JS files #noobMistake

anyway passing parameters on an insert can be done in the Azure mobile services library by passing them in after the initial object.

 client.getTable('myTable').insert(myJsonObj, <PARAMS HERE>);

they will be set to the parameters variable in the request object server side!