How to obtain the auto-generated ID from an item being Insterted in a Server Scripts, Windows Azure?

StackOverflow https://stackoverflow.com/questions/13573319

سؤال

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.
}
هل كانت مفيدة؟

المحلول

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();
        }
    });
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top