0
votes

I am trying to explicitly get the system properties from my table but it is not working. I can see that the URL is returning all the data including these fields if I use https://myservice.azure-mobile.net/tables/todoitem?__systemProperties=* but on the code I cannot get it as item.__version or item.version. I have tried adding todoitemtable = WindowsAzure.MobileServiceTable.SystemProperties.All; but no success! I have also looked at http://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-validate-modify-data-server-scripts/ but this is adding a new column instead of using the existing system columns.

$(function() { var client = new WindowsAzure.MobileServiceClient('https://ib-svc-01.azure-mobile.net/', 'key'); var todoItemTable = client.getTable('todoitem'); // = WindowsAzure.MobileServiceTable.SystemProperties.All;

// Read current data and rebuild UI.
// If you plan to generate complex UIs like this, consider using a JavaScript templating library.
function refreshTodoItems() {
    var query = todoItemTable.where({ complete: false });

    query.read().then(function(todoItems) {
        var listItems = $.map(todoItems, function(item) {
            return $('<li>')
                .attr('data-todoitem-id', item.id)
                .append($('<button class="item-delete">Delete</button>'))
                .append($('<input type="checkbox" class="item-complete">').prop('checked', item.complete))
                .append($('<div>').append($('<input class="item-text">').val(item.id))
        .append($('<span class="timestamp">' 
                + (item.createdAt && item.createdAt.toDateString() + ' '
                + item.createdAt.toLocaleTimeString() || '') 
                + '</span>')));
        });

        $('#todo-items').empty().append(listItems).toggle(listItems.length > 0);
        $('#summary').html('<strong>' + todoItems.length + '</strong> item(s)');
    }, handleError);
}

function handleError(error) {
    var text = error + (error.request ? ' - ' + error.request.status : '');
    $('#errorlog').append($('<li>').text(text));
}

function getTodoItemId(formElement) {
    return $(formElement).closest('li').attr('data-todoitem-id');
}

// Handle insert
$('#add-item').submit(function(evt) {
    var textbox = $('#new-item-text'),
        itemText = textbox.val();
    if (itemText !== '') {
        todoItemTable.insert({ text: itemText, complete: false }).then(refreshTodoItems, handleError);
    }
    textbox.val('').focus();
    evt.preventDefault();
});

// Handle update
$(document.body).on('change', '.item-text', function() {
    var newText = $(this).val();
    todoItemTable.update({ id: getTodoItemId(this), text: newText }).then(null, handleError);
});

$(document.body).on('change', '.item-complete', function() {
    var isComplete = $(this).prop('checked');
    todoItemTable.update({ id: getTodoItemId(this), complete: isComplete }).then(refreshTodoItems, handleError);
});

// Handle delete
$(document.body).on('click', '.item-delete', function () {
    todoItemTable.del({ id: getTodoItemId(this) }).then(refreshTodoItems, handleError);
});

// On initial load, start by fetching the current data
refreshTodoItems();

});

1
As per this link it is supported in JS but somehow it is not working!blogs.msdn.com/b/azuremobile/archive/2014/01/14/…user1866308
You did "todoItemTable.systemProperties = WindowsAzure.MobileServiceTable.SystemProperties.All;" correct? (i think you just had a typo in your question) What version of the JS SDK are you linking to?phillipv
ajax.aspnetcdn.com/ajax/mobileservices/… would be the current latest copy (although this should work in 1.1.3 as well, it would not work with 1.1.0)phillipv
Thanks a lot! updating to 1.1.5 worked like a charm!!! Don't know what the sample app's reference r not updated!user1866308

1 Answers

2
votes

I was trying to access the system properties from within the API scripts and found this and thought it was useful and relevant: http://www.brandonmartinez.com/2014/10/22/retrieve-system-properties-in-azure-mobile-services-javascript-backend/

Basically you can do this (example from the post):

myTable.read({
        systemProperties: ['__createdAt', '__updatedAt'],
        success: function(tableEntries) {
        // So on and so forth
    }
}