Hi there!
I've been working all day on a custom JavaScript expression in Survey123 and I feel like I'm SO close but I can't figure out what I'm missing.
The inspector we are working with wants to be able to see the TreeID of the last record submitted as they fill out the current survey. I'm using Ismael Chivite's template, 'getLastSubmittedRecord.js' which has been incredibly helpful, but I'm still getting an error result of "[object Object]" instead of a proper JSON response. I looked up this error and found it has something to do with requesting a JSON string instead of a Java Script object, so I'm confused why I am getting it when I'm requesting a JSON string.
See below for photos and script example
function getMyLastSubmittedRecord(username,token){
var featureLayer = "https://services.arcgis.com/3YWgO47sUznrJ4Fa/arcgis/rest/services/RCKC_Tree_Maintenance/FeatureServer";
var xmlhttp = new XMLHttpRequest();
var url = featureLayer + "/query?outFields=CreationDate&returnHiddenFields=false&returnGeometry=false&returnQueryGeometry=false&orderByFields=OBJECTID+DESC&resultRecordCount=1&f=json";
if (token && username){
url = url + "&token=" + token + "&where=Creator='" + username + "'";
} 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 responseJSON.error;
} else {
if (responseJSON){
return JSON.stringify(responseJSON);
}
else{
return "Never submitted before";
}
}
}
}
