Select to view content in your preferred language

Attribute query add-in - free solution provided

3800
5
01-21-2013 03:51 AM
PietaSwanepoel2
Frequent Contributor
Since we are not going to see a solution from the Silverlight team to easily query attributes in the application builder, I have finally built a solution to do so. This is a hack-in from the back into the configuration files and it is for me not the correct way to do it. But it is a solution

Provided is a Visual Studio 2010 solution. XAP file not included. It is based on the query example but much more user friendly. Feel free to use it. It is provided as is and I am NOT providing any support

PLEASE NOTE: The Viewer API does not contain options to obtain the fields with their settings as defined by the Application Builder. This tool assumes that definitions for the framework won???t change. If it does it could potentially break the functionality of the attribute query tool

The add-in will fail and not work within Application Builder. The configuration xml is different for the application builder than for a deployed site. Add the add-in and test it on a deployed site.

Note the following:
??? The tool uses the currently selected layer (only feature layers can be queried)
??? A new query results layer will be added for every type of feature (point, polyline and polygon). These will be replaced with new result sets for each query performed
??? No configuration is required as all the fields, as defined in the application builder, are used (the visibility settings and field alias names are used)
??? Operations are transformed to the appropriate format for the type of field it applies to, e.g. for a string ???=??? will be replaced with ???LIKE???, etc.
??? Values for string fields don???t need to be in quotes.
??? Wildcards don???t need to be used, e.g. if field value is ???METRO??? and operator ???=??? is used only value of ???METRO??? will match but for the operator ???LIKE??? the value of ???MET??? will match ???METRO???.
??? Wildcards are not used for the ???IN??? operation
??? The values are case sensitive, e.g. if field value is ???METRO??? the search term ???metro??? will not match. I am still working on solving this
??? Comma delimited values can be used for both string and numeric values, e.g. field ???OBJECTID??? values of ???1,2,3??? will match where OBJECTID=1, OBJECTID=2 AND OBJECTID=3

It has not been tested with dates, etc. Have tested strings and numeric values.
UPDATE: replace code with snippet below (date bit added). It is not in download

The were clause constructor is as follows:
Format for queryString is: {Field} {Operation} {Value}

            if (fType == Field.FieldType.String)
            {
                queryString = "{0} {1} '%{2}%'";
                if (operation == "=") queryString = "{0} LIKE '{2}'";
                if (operation == "IN") queryString = "{0} IN ('{2}')";
                if (operation == "NOT") queryString = "NOT {0} LIKE '{2}'";

                if (whereValue.Contains(",")) whereValue = whereValue.Replace(",", "','");
            }
            else if (fType == Field.FieldType.Date)
            {
                DateTime dt = new DateTime();
                bool b = DateTime.TryParse(whereValue, out dt);
                if (b == true)
                {
                    whereValue = dt.ToString("MM/dd/yyyy");
                    queryString = "{0} {1} '{2}'";
                    if (operation == "LIKE") queryString = "{0} = '{2}'";
                    if (operation == "IN") queryString = "{0} = '{2}'";
                    if (operation == "NOT") queryString = "{0} <> '{2}'";
                }
                else return;
            }
            else
            {
                queryString = "{0} {1} {2}";
                if (operation == "IN") queryString = "{0} IN ({2})";
                if (operation == "NOT") queryString = "{0} <> {2}";
            }
            if (operation == "IS NULL") queryString = "{0} IS NULL";
            if (operation == "NOT IS NULL") queryString = "NOT {0} IS NULL";


Hope it helps
0 Kudos
5 Replies
AlexeyTereshenkov
Deactivated User
Hi Pieta,

Great job! I am able to confirm that the add-in works as expected in a viewer application 3.0. I've built the solution in Visual Studio (was warned about the System.Windows.Interactivity library reference, but this is easily fixed by updating the .dll reference). Even without the update of the reference the solution compiles and the add-in can be added to the Viewer Application Builder though.

I was not able to figure out though how one can query the date fields.

I suggest you to upload the source code as well as .xap file since not all users might have Visual Studio at hand onto ArcGIS.com gallery. This will make your add-in discoverable for other community users. Instructions on uploading items are found at ArcGIS.com Help pages.
0 Kudos
IanPeebles
Frequent Contributor
This looks pretty cool.  I was able to build a .xap in visual studio.  However, when adding it to the viewer.  I specified a feature layer so I can select attributes.  On the query form, no fields are showing up from the drop down list.  All of the fields are visible.

I am using this service as a test: 

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0

Also, here is a screenshot of what I am seeing.  If the fields are visible and I am using a feature layer, I should be able to see the fields from the drop down list. . correct?  Let me know what I am doing wrong.

Also getting an error message when adding in the Points of Interest feature layer.

Any ideas?
0 Kudos
PietaSwanepoel2
Frequent Contributor
From my original post:

The add-in will fail and not work within Application Builder. The configuration xml is different for the application builder than for a deployed site. Add the add-in and test it on a deployed site.
0 Kudos
PietaSwanepoel2
Frequent Contributor
UPDATE:
Added date fieldtype to the code and included XAP in download. See attached file

Same settings apply as per original post

It is work in progress, fixing, changing and adding when I have time. So might change once again in future
0 Kudos
TomMagdaleno
Frequent Contributor
Thank you very much Pieta!  It works pretty good.  I see it adds a feature in the table of contents, then I right click and Go To.  Thats not a bad workflow.  I'm going to push this out to some more employees now that you have made it a useable program.
0 Kudos