I am trying to display a table in a Survey 123 form showing the last three values collected for questions on the form. I'm using a version based on Ishmael's examples at https://github.com/IsmaelInRedlands/Survey123-Tricks-of-the-Trade/blob/main/getLastSubmittedRecord.j.... I have gotten to the point of displaying the Json return in a null notes field, but it only displays the first record. The max record return for the service is the standard 2000. I have tried asking explicitly for a set number or leaving the &resultRecordCount= parameter out. Any thoughts on why only one record is returned?
The calculation is
pulldata("@javascript", "getRecord.js", "getRecords", ${qry_related_records}, "Voltage_Drop_Across_Shunt,Surveyor,Survey_Date", pulldata("@property","token"))
the query is
Parent_Test_Station_GUID='{4C1BF90A-2136-4905-B1E9-9DA0F39490EA}'
the script is
function getRecords(qry, fields, token){ var featureLayer = "https://services7.arcgis.com/#####/arcgis/rest/services/ServiceName/FeatureServer/0"; var xmlhttp = new XMLHttpRequest(); var url = featureLayer + "/query?outFields=" + fields + "&orderByFields=OBJECTID+DESC&f=json"; // &resultRecordCount=3 var url = url + "&where=" + qry if (token){ url = url + "&token=" + token; } else { return "You must be logged in"; } xmlhttp.open("GET",url,false); xmlhttp.send(); if (xmlhttp.status!==200){ return (xmlhttp.status); } else { var responseJSON=JSON.parse(xmlhttp.responseText) if (responseJSON.error){ return (JSON.stringify(responseJSON.error)); } else { if (responseJSON.features[0]){ return JSON.stringify(responseJSON.features); } else{ return "Never submitted before"; } } }}
it returns
Thrilled to get the most recent record based on the descending sort on object id, but really would like all three records I know exist.
My next step will be converting the Json to an html table for display).
Solved! Go to Solution.
This is my first time deploying a script with S123 or writing a JavaScript function to begin with. So, my hunch is that the JavaScript does not update fully unless one drops out of the S123 app and re-launches. I had been updating the survey with each edit to the script, but not seeing responses in the return. once I dropped out of the s123 app entirely, and relaunched it, the changes appeared. Thanks to Neal-Kittelson for getting me to throw a brick at it.
Did you try querying with your parameters directly from the ArcGIS REST Services Directory page for your layer to see what you get? If you are getting one record but not all you are expecting are you sure you have the proper where statement? Try where 'Parent_Test_Station_GUID is not null' and see what you get?
This is my first time deploying a script with S123 or writing a JavaScript function to begin with. So, my hunch is that the JavaScript does not update fully unless one drops out of the S123 app and re-launches. I had been updating the survey with each edit to the script, but not seeing responses in the return. once I dropped out of the s123 app entirely, and relaunched it, the changes appeared. Thanks to Neal-Kittelson for getting me to throw a brick at it.