I have a box in my survey for sample numbers and I'd love to prepopulate it with a calculation. The sample number is always X+1, where X is the previously collected sample number. Is it possible to pull data from the most recently submitted survey so I can get this X?
Thanks!
Solved! Go to Solution.
Hi Kate,
No, it is not possible to query data locally on the device from a previously submitted record.
However, you could use a custom JavaScript function and the pulldata @ JavaScript feature to query the feature layer and return the last submitted value for the sample number field. This would require the user and device to be online and have access to the feature layer, and only work when the previous record has already been submitted (ie not in the Drafts or Outbox).
Check out JavaScript functions in survey forms—ArcGIS Survey123 | Documentation and https://community.esri.com/groups/survey123/blog/2020/08/07/extending-survey123-smart-forms-with-cus... for more information.
Otherwise check out this blog post which relates to auto-incrementing "ticket numbers" which sounds similar to what you are wanting to do https://community.esri.com/groups/survey123/blog/2017/11/25/creating-ticket-numbers-in-survey123-for....
Regards,
Phil.
Hi Kate,
No, it is not possible to query data locally on the device from a previously submitted record.
However, you could use a custom JavaScript function and the pulldata @ JavaScript feature to query the feature layer and return the last submitted value for the sample number field. This would require the user and device to be online and have access to the feature layer, and only work when the previous record has already been submitted (ie not in the Drafts or Outbox).
Check out JavaScript functions in survey forms—ArcGIS Survey123 | Documentation and https://community.esri.com/groups/survey123/blog/2020/08/07/extending-survey123-smart-forms-with-cus... for more information.
Otherwise check out this blog post which relates to auto-incrementing "ticket numbers" which sounds similar to what you are wanting to do https://community.esri.com/groups/survey123/blog/2017/11/25/creating-ticket-numbers-in-survey123-for....
Regards,
Phil.
From what I understood Philip, I would be able to use java to get the last record inside a repeat. These links do not include the last record submitted to the survey.
Is there anything that I am missing?
Hi @AnaDeniston,
As mentioned in chat, the only way you can get a value from a previous record if after it is submitted and hosted int he feature layer, if you know the ID or a way to look it up. There are some other options you could try:
Here is a blog to search() appearance: Dynamic Choice Lists using Search Appearance - Esri Community
Also here is the doc for Linked Content: https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformessentials.htm#ESRI_SECTION1_34A4D...
Otherwise the best option is still to use a JS function.
Regards,
Phil.
Heey Kate,
Were you able to figure out how to do this? I am running into the same issue.
Thanks
Hi @KateBerg2 and @AnaDeniston
Did either of you figure this out?
Hi Jerry,
Yes, I created a script that pulls the data from ArcGIS online feature layer.
Here is the script:
function myfunction(token, debugmode){
var featureLayer = "https://services.arcgis.com/....../FeatureServer/0"; #URL of the feature layer
var xmlhttp = new XMLHttpRequest();
var url = featureLayer + "/query?where=1=1&outFields=*&f=json"
if (token){
url = url + "&token=" + token;
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
if (xmlhttp.status!==200){
return (debugmode? xmlhttp.status:"");
} else {
var responseJSON=JSON.parse(xmlhttp.responseText)
if (responseJSON.error){
return (debugmode? JSON.stringify(responseJSON.error):"");
} else {
if (responseJSON.features[0]){
return JSON.stringify(responseJSON.features[responseJSON.features.length - 1]);
}else{
return (debugmode? "No Features Found":"");
}
}
}
}
This is what my XLSForm looks like:
Notice that you can get any attribute that you want from the last reads by using this:
pulldata("@json", ${myJava}, "attributes.Date")
Let me know if you have any questions,
Ana
Hi Ana. Thank you very much for sharing your solution, super helpful.
Question: Is your JS function taking any of the users responses as parameters for the pulldata function? Sorry for the noob question, I am not familiar with JS. In my scenario, I need a user to select a location, then for my JS function to pull a quantity from the last time that location had a survey submitted.
Thank you in advance for any insight!