Query Widget does not show results for Feature joined with view

2771
2
Jump to solution
01-28-2016 02:48 PM
MatthewTownsend
New Contributor II

For comparison sake I created two similar features in the MXD.

The first named, named Electric Service Point consists of the Feature (ServicePointBank) joined with a table (ServicePoint) further joined with a view that get's its data across a db link to another database.

The second, named Electric Service Point Query consists of the Feature (ServicePointBank) joined with the table (ServicePoint).

In short, the only difference between the two is that the first Feature has the view joined with it.

These are published to a service, which is consumed by a web map.

I am then using Web AppBuilder Developer Edition (version 1.3) and am using the web map.  I configured the Query Widget identically for both Features.  They are configured to query against a field on the ServicePoint table.

Results:

For the first feature, it displays "Number of features found: 1) in the query results but does NOT list the feature or show the graphic on the map.

For the second feature, it displays the same but ALSO lists the feature and shows the graphic on the map.  The problems that I really need the data from that view and I do NOT want to have two layers in the layer list as it confuses our users.

Looking in the Firefox debugger is see that both features call:

First Feature:

https://gisdev.avistacorp.com/arcgis/rest/services/DEV/MattsQueryTest/MapServer/1/query?f=json&retur...

https://gisdev.avistacorp.com/arcgis/rest/services/DEV/MattsQueryTest/MapServer/1/query?f=json&where...

Second Feature:

https://gisdev.avistacorp.com/arcgis/rest/services/DEV/MattsQueryTest/MapServer/5/query?f=json&retur...

https://gisdev.avistacorp.com/arcgis/rest/services/DEV/MattsQueryTest/MapServer/5/query?f=json&retur...

But the second feature is the only one that even tries to call:

https://gisdev.avistacorp.com/arcgis/rest/services/DEV/MattsQueryTest/MapServer/5/query?f=json&retur...

I didn't really notice much of a difference debugging through the Widget code but I am not familiar with it or with java script in general so there is a good chance I missed something.

Has anybody seen (and hopefully found a way around) this?

1 Solution

Accepted Solutions
MatthewTownsend
New Contributor II

After talking with ESRI support we modified the Query Widget Javascript slightly to get it working.

The problem is that if it has a joined view it returns an empty feature list for the results of an object ID query.

Basically I modified it to always do the backup query using the objectID field name (in my case SDEADMIN.ServicePointBank.ObjectID).  The issue in this case was that the feature with the view joined to it was NOT getting an error.  Instead it was returning "successfully" with a count of 1 but an empty feature collection.  The downside to the change below is that for multiple results you will more quickly run into the max URI length.  Seems to me that the best option would be to just get the feature result from the original query (in my case SPID = 'some number') rather than getting the object IDs from that query and then querying again using the object IDs as the Widget is currently setup to do.  For now, this change will do.

Old code from Query/SingleTask.js:

_queryByObjectIds: function(objectIds, returnGeometry){

        var def = new Deferred();

        var queryParams = new EsriQuery();

        queryParams.returnGeometry = !!returnGeometry;

        queryParams.outSpatialReference = this.map.spatialReference;

        queryParams.outFields = this._getOutputFields();

        queryParams.objectIds = objectIds;

        var queryTask = new QueryTask(this.currentAttrs.config.url);

        queryTask.execute(queryParams).then(lang.hitch(this, function(response){

          def.resolve(response);

        }), lang.hitch(this, function(err){

          if(err.code === 400){

            //the query fails maybe becasuse the layer is a joined layer

            //joined layer:

            //http://csc-wade7d:6080/arcgis/rest/services/Cases/ParcelWithJoin/MapServer/0

            //joined layer doesn't support query by objectIds direcly, so if the layer is joined,

            //it will go into errorCallback of queryTask.

            //the alternative is using where to re-query.

            var objectIdField = this._getObjectIdField();

            var where = "";

            var count = objectIds.length;

            array.forEach(objectIds, lang.hitch(this, function(objectId, i){

              where += objectIdField + " = " + objectId;

              if(i !== count - 1){

                where += " OR ";

              }

            }));

            this._query(where, null, returnGeometry).then(lang.hitch(this, function(response){

              def.resolve(response);

            }), lang.hitch(this, function(err){

              def.reject(err);

            }));

          }else{

            def.reject(err);

          }

        }));

        return def;

      },

New Code:

_queryByObjectIds: function(objectIds, returnGeometry){

        var def = new Deferred();

        var queryParams = new EsriQuery();

        queryParams.returnGeometry = !!returnGeometry;

        queryParams.outSpatialReference = this.map.spatialReference;

        queryParams.outFields = this._getOutputFields();

        var where = "";

        var objectIdField = this._getObjectIdField();

        var length = objectIds.length;

        array.forEach(objectIds, lang.hitch(this, function (objectId, i) {

            where += objectIdField + " = " + objectId;

            if (i !== length - 1) {

                where += " OR ";

            }

        }));

        queryParams.where = where;

        var queryTask = new QueryTask(this.currentAttrs.config.url);

        queryTask.execute(queryParams).then(lang.hitch(this, function(response){

          def.resolve(response);

        }), lang.hitch(this, function(err){ def.reject(err); }));

        return def;

      },

View solution in original post

2 Replies
MatthewTownsend
New Contributor II

After talking with ESRI support we modified the Query Widget Javascript slightly to get it working.

The problem is that if it has a joined view it returns an empty feature list for the results of an object ID query.

Basically I modified it to always do the backup query using the objectID field name (in my case SDEADMIN.ServicePointBank.ObjectID).  The issue in this case was that the feature with the view joined to it was NOT getting an error.  Instead it was returning "successfully" with a count of 1 but an empty feature collection.  The downside to the change below is that for multiple results you will more quickly run into the max URI length.  Seems to me that the best option would be to just get the feature result from the original query (in my case SPID = 'some number') rather than getting the object IDs from that query and then querying again using the object IDs as the Widget is currently setup to do.  For now, this change will do.

Old code from Query/SingleTask.js:

_queryByObjectIds: function(objectIds, returnGeometry){

        var def = new Deferred();

        var queryParams = new EsriQuery();

        queryParams.returnGeometry = !!returnGeometry;

        queryParams.outSpatialReference = this.map.spatialReference;

        queryParams.outFields = this._getOutputFields();

        queryParams.objectIds = objectIds;

        var queryTask = new QueryTask(this.currentAttrs.config.url);

        queryTask.execute(queryParams).then(lang.hitch(this, function(response){

          def.resolve(response);

        }), lang.hitch(this, function(err){

          if(err.code === 400){

            //the query fails maybe becasuse the layer is a joined layer

            //joined layer:

            //http://csc-wade7d:6080/arcgis/rest/services/Cases/ParcelWithJoin/MapServer/0

            //joined layer doesn't support query by objectIds direcly, so if the layer is joined,

            //it will go into errorCallback of queryTask.

            //the alternative is using where to re-query.

            var objectIdField = this._getObjectIdField();

            var where = "";

            var count = objectIds.length;

            array.forEach(objectIds, lang.hitch(this, function(objectId, i){

              where += objectIdField + " = " + objectId;

              if(i !== count - 1){

                where += " OR ";

              }

            }));

            this._query(where, null, returnGeometry).then(lang.hitch(this, function(response){

              def.resolve(response);

            }), lang.hitch(this, function(err){

              def.reject(err);

            }));

          }else{

            def.reject(err);

          }

        }));

        return def;

      },

New Code:

_queryByObjectIds: function(objectIds, returnGeometry){

        var def = new Deferred();

        var queryParams = new EsriQuery();

        queryParams.returnGeometry = !!returnGeometry;

        queryParams.outSpatialReference = this.map.spatialReference;

        queryParams.outFields = this._getOutputFields();

        var where = "";

        var objectIdField = this._getObjectIdField();

        var length = objectIds.length;

        array.forEach(objectIds, lang.hitch(this, function (objectId, i) {

            where += objectIdField + " = " + objectId;

            if (i !== length - 1) {

                where += " OR ";

            }

        }));

        queryParams.where = where;

        var queryTask = new QueryTask(this.currentAttrs.config.url);

        queryTask.execute(queryParams).then(lang.hitch(this, function(response){

          def.resolve(response);

        }), lang.hitch(this, function(err){ def.reject(err); }));

        return def;

      },

BugPie
by
Occasional Contributor III

Hi there - fairly old thread but I found myself in this situation this week. I'm using the widget from my Portal so I am unable to adjust the code unless I put the web app on my own IIS server. Which I woudl like to do, just not on the short list right now.

I'm trying to get additional attributes from a different SQL db table to a point feature that has a related (relationship class exists within gdb)table in the same gdb as the point feature.  As soon as I publish a service with this join in place, the widget fails in the way you have explained. 

My questions is whether or not you ever found another solution and if you think there is any work around within if I'm using this widget from a Portal hosted web app? Mayeb I need to run a process to move teh attributes from teh joined table directly to the related table or point feature itself? IDK, struggling to identify the problem so I can craft my approach.