OrderBy not working on Qt

1193
5
Jump to solution
02-10-2017 07:33 AM
Marco_AlejandroBonilla
Occasional Contributor

Hi all,

We're tying to obtain the last 10 records added to a Feature Layer.

We're using OrderBy to accomplish this task but it's not working.

Please, any help is more than welcome.

        QueryParameters{

               id: paramsQuery

                whereClause: "1=1"

                maxFeatures: 10

                orderByFields: [ OrderBy { fieldName: "OBJECTID"; sortOrder: Enums.SortOrderDescending} ]

   }

 

        map.operationalLayers.get(0).featureTable.queryFeatures(paramsQuery);

result:

 

qml: OBJECTID 7959 IDInstalacion SAN000001A

qml: OBJECTID 7960 IDInstalacion SAN000002A

qml: OBJECTID 7961 IDInstalacion SAN000003A

qml: OBJECTID 7962 IDInstalacion SAN000004A

qml: OBJECTID 7963 IDInstalacion SAN000005A

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Marco-

I tried your code and it works for me (the order prints out descending). Then, I realized that I am testing with a local build of Update 1, and not the 100.0 final release. This is a bug with the final release of 100.0 that we have recently fixed, and that you will get with the release of Update 1. Apologies for the confusion!

-Luke

View solution in original post

5 Replies
LucasDanzinger
Esri Frequent Contributor

Hmm, it seems to be working from my test. Maybe you can share a repro case with some test data? Here is what I am doing:

QueryParameters {
    id: orderByQuery
    whereClause: "1=1"
    maxFeatures: 10
    orderByFields: [
        OrderBy {
            fieldName: "OBJECTID"
            sortOrder: Enums.SortOrderDescending
        }
    ]
}‍‍‍‍‍‍‍‍‍‍‍

Then I have a test function:

// tests orderBy QueryParameters in queryFeatures
function test_0253_ServiceFeatureTableQueryFeaturesOrderBy() {
    serviceFeatureTable.queryFeatures(orderByQuery);
    compare(serviceFeatureTable.queryFeaturesStatus, Enums.TaskStatusInProgress);
    verify(Utils.waitForTaskStatusCompleted(serviceFeatureTable, serviceFeatureTableUnitTests, "queryFeaturesStatus"));
    compare(serviceFeatureTable.queryFeaturesStatus, Enums.TaskStatusCompleted);

    while (serviceFeatureTable.queryFeaturesResult.iterator.hasNext) {
        var feature = serviceFeatureTable.queryFeaturesResult.iterator.next();
        console.log(JSON.stringify(feature.attributes.attributesJson))
    }
}

And this prints out:

qml: {"GLOBALID":"96BB8A4A-F847-441E-B5BD-FCFC4D0ED336","OBJECTID":12303,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"3BB033A3-B4B6-4407-835A-A43A4028240F","OBJECTID":11892,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"0757C598-4FE4-4DDD-A71F-5F5B6D9A1188","OBJECTID":11891,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"24F0E648-BC2E-4D2B-A5E2-BC037D173DE1","OBJECTID":11890,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"1EA5D5D9-9086-4E8A-B490-9E394678C2B8","OBJECTID":11889,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"9EEAAA46-3C3C-4716-A30E-8603DCD6A7F3","OBJECTID":11888,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"2BA75D97-978B-4690-A70B-9D4EC6698213","OBJECTID":11887,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"EB41D73F-207F-40F2-9221-9FAEBCE25068","OBJECTID":11886,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"E6131832-2F87-4D66-8ADD-1B3681D864D8","OBJECTID":11505,"PLACENAME":null,"TYPDAMAGE_INT":1}
qml: {"GLOBALID":"E8BAE8E2-DE99-4DEE-A326-D9F1AEB82C96","OBJECTID":11504,"PLACENAME":null,"TYPDAMAGE_INT":1}

If I switch to ascending, I get this:

qml: {"GLOBALID":"8B68F79B-1B4D-4139-89F4-3EF532EA9957","OBJECTID":3,"PLACENAME":null,"TYPDAMAGE_INT":3}
qml: {"GLOBALID":"D11EA625-F08C-4535-9482-DD4ACB080FB9","OBJECTID":804,"PLACENAME":"Q bld","TYPDAMAGE_INT":5}
qml: {"GLOBALID":"3124D0B1-E56D-405E-BC63-2A162654C29E","OBJECTID":807,"PLACENAME":"H bld","TYPDAMAGE_INT":3}
qml: {"GLOBALID":"81B3E1EA-09BA-4600-B359-C4A68051CF41","OBJECTID":808,"PLACENAME":"HR","TYPDAMAGE_INT":1}
qml: {"GLOBALID":"EF6C4488-7AC4-4345-A454-BC04D5C4DC16","OBJECTID":813,"PLACENAME":"Esri","TYPDAMAGE_INT":5}
qml: {"GLOBALID":"A409DC80-715F-4504-A553-A1701EFBD354","OBJECTID":814,"PLACENAME":"Storage","TYPDAMAGE_INT":2}
qml: {"GLOBALID":"01203C5F-A4D1-4B29-87B1-4060E3C15CFC","OBJECTID":815,"PLACENAME":"Palm Springs Aerial Tramway","TYPDAMAGE_INT":1}
qml: {"GLOBALID":"53DD78A1-AA0E-4077-BDF7-63EBB5394634","OBJECTID":1201,"PLACENAME":"Benjarong","TYPDAMAGE_INT":5}
qml: {"GLOBALID":"2E0BC8FD-5095-426B-A2FC-2B0C0B21D86F","OBJECTID":1207,"PLACENAME":"Esri","TYPDAMAGE_INT":4}
qml: {"GLOBALID":"F6C38A29-BAE8-47B5-90A8-CB0C53BAE845","OBJECTID":1208,"PLACENAME":"Esri","TYPDAMAGE_INT":2}
0 Kudos
Marco_AlejandroBonilla
Occasional Contributor

Hi Lucas,

Thanks for your reply.

We don't know if we're missing anything but it's not working for us. Here's our code and, as you can see, is being run on an arcgis sample service.

import QtQuick 2.6

import QtQuick.Controls 1.4

import QtQuick.Controls.Styles 1.4

import QtQuick.Dialogs 1.2

import Esri.ArcGISRuntime 100.0

import Esri.ArcGISExtras 1.1

 

ApplicationWindow {

    width: 800

    height: 600

 

    property real scaleFactor: System.displayScaleFactor

 

    // Map view UI presentation at top

    MapView {

        id: mapView

 

        anchors.fill: parent

        wrapAroundMode: Enums.WrapAroundModeDisabled

 

        Map {

            id: map

            BasemapTopographic {}

            initialViewpoint: ViewpointCenter {

                id: viewPoint

                center: Point {

                    x: -11e6

                    y: 5e6

                    spatialReference: SpatialReference {

                        wkid: 102100

                    }

                }

                targetScale: 9e7

            }

            FeatureLayer {

                id: featureLayer

                // feature table

                ServiceFeatureTable{

                        id: serviceFeatureTable

                        url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"

                        onQueryFeaturesStatusChanged: {

                            console.log("status", queryFeaturesStatus)

                            if(queryFeaturesStatus === Enums.TaskStatusCompleted){

                                while (queryFeaturesResult.iterator.hasNext) {

                                    var feature = queryFeaturesResult.iterator.next();

                                    console.log(JSON.stringify(feature.attributes.attributesJson))

                                }

                            }

                        }

                    }

            }

        }

 

        Button {

            text: "Find and Select"

            enabled: serviceFeatureTable.loadStatus === Enums.LoadStatusLoaded

            onClicked: {

                query();

            }

        }

     }

    QueryParameters{

      id: orderByQuery

       whereClause: "1=1"

       maxFeatures: 10

       orderByFields: [

           OrderBy {

               fieldName: "objectid";

               sortOrder: Enums.SortOrderDescending

           }

       ]

      }

 

    // function to form and execute the query

    function query() {

        // start the query

        serviceFeatureTable.queryFeatures(orderByQuery);

    }

}

 

This is the result we get:

qml: status 1

qml: status 2

qml: {"objectid":12,"state_name":"Oregon"}

qml: {"objectid":11,"state_name":"Minnesota"}

qml: {"objectid":23,"state_name":"Nevada"}

qml: {"objectid":13,"state_name":"New Hampshire"}

qml: {"objectid":14,"state_name":"Iowa"}

qml: {"objectid":15,"state_name":"Massachusetts"}

qml: {"objectid":16,"state_name":"Nebraska"}

qml: {"objectid":24,"state_name":"Utah"}

qml: {"objectid":17,"state_name":"New York"}

qml: {"objectid":18,"state_name":"Pennsylvania"}

cc jimy cuesta

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Marco-

I tried your code and it works for me (the order prints out descending). Then, I realized that I am testing with a local build of Update 1, and not the 100.0 final release. This is a bug with the final release of 100.0 that we have recently fixed, and that you will get with the release of Update 1. Apologies for the confusion!

-Luke

View solution in original post

Marco_AlejandroBonilla
Occasional Contributor

Lucas,

Thanks for the info, maybe you know when the update is being released?

Marco B.

LucasDanzinger
Esri Frequent Contributor