Search code examples
javascriptsortingcloudkit

Sort records by timestamp in Cloudkit.JS


I'm trying to sort these records by its created timestamp, but I'm using the cloudkit-js sample codes as a base. I see that they have a sortBy section but it requires the use of a fieldName, which isn't what I want to sort by. I need to sort by metadata, not input. Here's where the problem occurs

var query = {
        recordType: 'Locations',
        sortBy: [{
             fieldName: '*don't know what to put here*'
        }]

};

If I put in fieldName, any of the fields I create below, like placename, or category (there are many more but I edited them out since unnecessary), it'll sort the records fine by those fieldNames. But I don't know what to put in order to sort by record['created'].timestamp. Because if I put 'created' or 'record' in fieldName, they aren't fieldNames, hence an error. So is there a different thing to write than fieldName inside sortBy or what?

This is where the table is created plus its fields

records.forEach(function(record) {
        var fields = record.fields;
        var tableActual = "<tr><td>" + record['created'].timestamp + "</td><<td>" + fields['placeName'].value + "</td><td>" + fields['category'].value + ...

Solution

  • Currently, in order to sort by create time you have to do it like this:

    sortBy: [{ fieldName: '___createTime', ascending: true }]
    

    There should be a better alias and it should be documented, but this is a known bug.