Eksportér (0) Udskriv
Udvid alt
EN
Dette indhold er ikke tilgængeligt på dit sprog, men her er den engelske version.

Using scripts

Updated: April 15, 2014

For a JavaScript backend mobile service, you can register JavaScript code that is executed by the service when an insert, update, delete, or query operation occurs against a specific table. The name of the function must match the name of the specific operation, except for the delete operation, which must be named del. These scripts provide the ability to inject business logic into table operation, stop an operation from taking place, change values supplied to the operation or change the results. For authenticated clients, you can also perform user-specific authorizations based on the userId value of the supplied user object.

A .NET backend mobile service provides this functionality using classes that derive from TableController<TData>. There is no support in the Management Portal for .NET backend data operations.

To register a script in a JavaScript backend mobile service, select the desired Operation in the portal, then modify the provided function definition to add your business logic to the function.

The following is a script that can be associated with an insert operation:

function insert(item, user, request) {
    if (!item.approved) handleUnapprovedItem(item, request);
    else request.execute();
}

function handleUnapprovedItem(item, request) {
    // Do something here. 
}

This function checks the value if the approved property of the item and calls a helper function when the value is false. For more information about scripts, see Mobile Services server script reference.

Vis:
© 2014 Microsoft