How Do I Get Records Length From A QueryTask?

3705
6
Jump to solution
06-11-2015 02:08 PM
ChrisSergent
Regular Contributor III

I have entered in the parameters for a query here: Query: Sign (ID: 0)

I return a total of 8 signs in this query, but I want to connect the returned information to a form using previous and next buttons to increment or decrement by one for each button click to assign that specific record to the form and then switch forms once the max or minimum number has been reached.

Just to be safe, my parameters were as follows:

Where: SUPPORTID='691'

Out Fields: *

Order By Fields: OBJECTID

Everything else was the default.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Chris,

   So when you run the initial query you get an array of features. So just use that array of features and use your position in the array (your index)  to return the individual record from your array when the user clicks next just add to your index var.

var myArr = queryResuts.features;

var myRecLen = myArr.length - 1;

var myIndex = 0;

var frmRec = myArr[myIndex];

//next button clicked

myIndex++;

if(myIndex <= myRecLen){

     frmRec = myArr[myIndex];

}else{

     myIndex = myRecLen;

     frmRec = myArr[myRecLen];

}

//previous button clicked

myIndex--;

if(myIndex >= 0){

     frmRec = myArr[myIndex];

}else{

     myIndex = 0;

     frmRec = myArr[0];

}

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Chris,

   Not sure I understand the question here but this url will get you just the count:

http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0/query?where=SUPPO...

0 Kudos
ChrisSergent
Regular Contributor III

I do know how to do that. Maybe this video will help:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

   So when you run the initial query you get an array of features. So just use that array of features and use your position in the array (your index)  to return the individual record from your array when the user clicks next just add to your index var.

var myArr = queryResuts.features;

var myRecLen = myArr.length - 1;

var myIndex = 0;

var frmRec = myArr[myIndex];

//next button clicked

myIndex++;

if(myIndex <= myRecLen){

     frmRec = myArr[myIndex];

}else{

     myIndex = myRecLen;

     frmRec = myArr[myRecLen];

}

//previous button clicked

myIndex--;

if(myIndex >= 0){

     frmRec = myArr[myIndex];

}else{

     myIndex = 0;

     frmRec = myArr[0];

}

ChrisSergent
Regular Contributor III

I'll try adding this code in with the query and let you know how it goes.

0 Kudos
ChrisSergent
Regular Contributor III

I need to figure this out: How Do I Return An Array From My Query?  before I can try your code here.

0 Kudos
ChrisSergent
Regular Contributor III

This is what how I want to navigate the form. Thanks.

0 Kudos