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();
}
});
}