How do I exclude a selected value from a query but keep it for my array?

4072
12
Jump to solution
06-30-2015 12:44 PM
ChrisSergent
Regular Contributor III

When I run a query, I have one of the values already selected that would be returned. If I populate my form as is, one of the values will be the selected item meaning it will be displayed twice. How do I exclude it for my first navigation, but display it if I navigate back to it?

Here is the code:

// Show supports form for updating
            document.getElementById("btnSupportUpdate").style.visibility = "visible";
            app.attributesModal.modal("show");


            ii = -1;




           
        });
        /* Update Support Layer End */


        // Cycle through sign information with the previous button
        on(dom.byId("btnSupportPrevious"),"click",function(){
            console.log("Previous Works");
            var query = new esriQuery();
            var queryTask = new QueryTask(config.signLayerUrl);
            query.returnGeometry = false;
            query.outFields = ["*"];






            query.where = "SUPPORTID = " + dom.byId("supportId").value;
            queryTask.execute(query, function (results) {
                ii--;
                // Attempting to know how many signs are in my results
                // Use gettArray.html to get array values




                var resultItems = [];
                var resultCount = results.features.length;
                if (ii > -1) {
                    console.log("Results start now!");
                    console.log(results);
                    var featureAttributes = results.features[ii].attributes.GLOBALID;
                    for (var attr in featureAttributes) {
                        console.log("Attribute: " + featureAttributes);
                    }


                } else {
                    console.log("This is where you will get the support information");
                    //document.getElementById("btnSupportNext").disabled = true;
                }




            })
        });
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

Yes. you need to compare the ObjectId of the clicked object with the one from Query and set the value of ii variable to the appropriate index. so that your next/previous will work like normal.

View solution in original post

12 Replies
thejuskambi
Occasional Contributor III

Try to keep the query result as part of the global and try to avoid quering the service everytime you click next and previous button. That way you can simplfy you loading logic. Try query only once when you show the dialog and clear it when you hide.

ChrisSergent
Regular Contributor III

I can see running the query before the click event. I was thinking maybe a function. I had not thought about clearing the query after the form closed. I went here: QueryTask | API Reference | ArcGIS API for JavaScript  but did not see a way to clearing the query unless I should just set it to nothing. But even when I do it that way, I have one of my items in the form that opens. I just want it to exclude that item.

I do have a unique value on my form which is the objectID

Would this work; just pseudocode:

If current objectid on form = objectId in array  next i

I was thinking that this will cause the item already on the form to be skipped.

What do you think?

0 Kudos
thejuskambi
Occasional Contributor III

Query/QueryTask are just object which you need to the result. important is the FeatureSet result which you get after excution. I know you had shared you code some where. Could you share the link again please so that I can have a look at the complete application.

ChrisSergent
Regular Contributor III
0 Kudos
thejuskambi
Occasional Contributor III

I dont see any implementation for updating the dialog on next and previous button click. is that right?

0 Kudos
ChrisSergent
Regular Contributor III

That's correct. The item that I am getting in the console.log will be used to update. I just wanted to skip it if it displayed both in the console.log and and the form which is the value of the supportId.

0 Kudos
thejuskambi
Occasional Contributor III

I dont think you need to worry about that as the current index is maintain by the variable ii and it will always be more or less then the current index. Just make sure that you use order by of a particular unique id fields to ensure that each time you get the result, you get it in the same order.

ChrisSergent
Regular Contributor III

My concern is that the first item in the form is not populated by the array, It's populated by the click event. I could populate it by the array instead and run the query on the feature click event, I think.

0 Kudos
thejuskambi
Occasional Contributor III

You have 2 different layer, Support and Signs. On click of support layer you get the graphic of support layer, whereas in the query you are using Signs layer. so as soon as you do next or previous and update the form, your originally clicked object/graphic will be lost.

On the other hand, when you click on Signs layers, you query for the same layer so, you may not be losing the original object but as you are aware you will have the same object repeated. so you would need to ignore the original object and get the selected object from the query result based on object ID and at that time initialize the ii variable to the index of the required object.

Does this make sense?