Is it possible to pull data from the most recently submitted survey?

2274
7
Jump to solution
08-13-2020 12:32 PM
KateBerg2
New Contributor III

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!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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.

View solution in original post

7 Replies
by Anonymous User
Not applicable

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.

AnaDeniston
New Contributor III

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?

0 Kudos
by Anonymous User
Not applicable

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.

AnaDeniston
New Contributor III

Heey Kate, 

Were you able to figure out how to do this? I am running into the same issue.

Thanks

0 Kudos
JerrySneary
New Contributor III

Hi @KateBerg2 and @AnaDeniston 

Did either of you figure this out?

0 Kudos
AnaDeniston
New Contributor III

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:

AnaDeniston_0-1668463192056.png

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

0 Kudos
RodrigoLopez
New Contributor II

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!

0 Kudos