Question

I got a table, "Plan" with a few columns and a ID column that's autogenerated when insert. When i'm working in the Insert server script, how can I know the ID?. I'm working on windows azure mobile service.

function insert(item, user, request) {
    //I want to know the ID of the new item to be inserted.
}
Was it helpful?

Solution

The id is only generated when the item is inserted in the database, and it's added as a new property to the item parameter. You can get to it by specifying a callback to the script in the insert operation:

function insert(item, user, request) {
    request.execute({
        success: function() {
            var id = item.id;
            console.log("The new item's id is: ", id);
            request.respond();
        }
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top