Answered by:
Getting Table Context on Server-Side Script

Question
-
I've noticed in a number of the examples so far it seems that the server-side scripts for table operations have no concept of context with regards to which table they are being executed on. Is there any way to grab the table name rather than hard coding it into server side scripts?Monday, August 12, 2013 1:01 AM
Answers
-
I got you. No currently there is nothing like that I am aware of. This would be a neat feature to request on UserVoice however!
https://mobileservices.uservoice.com/forums/182281-feature-requests
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Proposed as answer by Jeff SandersMicrosoft employee Tuesday, August 13, 2013 12:54 PM
- Marked as answer by ColinBowern Wednesday, August 14, 2013 6:34 PM
Tuesday, August 13, 2013 12:54 PM -
Yes, you can use the 'current' property on the tables object (the documentation still needs to be updated to include this property). See the insert script below for an example of how this can be used.
function insert(item, user, request) { var currentTable = tables.current; currentTable.where({ name: item.name }).read({ success: function (items) { if (items.length > 0) { request.respond(400, { error: 'Item with this name already exists' }); } else { request.execute(); } } }); }
Carlos Figueira
- Proposed as answer by CarlosFigueiraMicrosoft employee Thursday, August 15, 2013 5:05 PM
- Edited by CarlosFigueiraMicrosoft employee Thursday, August 15, 2013 5:05 PM
- Marked as answer by ColinBowern Friday, August 16, 2013 12:18 AM
Thursday, August 15, 2013 5:05 PM
All replies
-
The scripts do execute in the context of the Table they are operating on. Can you give a concrete example of what you are trying to accomplish in your script?
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)Monday, August 12, 2013 3:04 PM -
I'm talking about code inside the table scripts where you want to do something specific on the current table. Right now you need to do:
var table = tables.getTable('MyTable'); table.where({ ... condition ... }) .read({ success: function(results) { if (!results.length) request.execute(); }});
There seems to be no easy way to infer the current operation is happening on a specific table. I would be looking for some sort of request.target or request.table property to detect what the current inbound request will operate on so I don't need to hard code the getTable call and can easily reuse scripts.
Monday, August 12, 2013 3:11 PM -
I got you. No currently there is nothing like that I am aware of. This would be a neat feature to request on UserVoice however!
https://mobileservices.uservoice.com/forums/182281-feature-requests
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Proposed as answer by Jeff SandersMicrosoft employee Tuesday, August 13, 2013 12:54 PM
- Marked as answer by ColinBowern Wednesday, August 14, 2013 6:34 PM
Tuesday, August 13, 2013 12:54 PM -
Thanks - I must have missed the WMS user voice forum when looking at the community resources.Wednesday, August 14, 2013 6:34 PM
-
Yes, you can use the 'current' property on the tables object (the documentation still needs to be updated to include this property). See the insert script below for an example of how this can be used.
function insert(item, user, request) { var currentTable = tables.current; currentTable.where({ name: item.name }).read({ success: function (items) { if (items.length > 0) { request.respond(400, { error: 'Item with this name already exists' }); } else { request.execute(); } } }); }
Carlos Figueira
- Proposed as answer by CarlosFigueiraMicrosoft employee Thursday, August 15, 2013 5:05 PM
- Edited by CarlosFigueiraMicrosoft employee Thursday, August 15, 2013 5:05 PM
- Marked as answer by ColinBowern Friday, August 16, 2013 12:18 AM
Thursday, August 15, 2013 5:05 PM