Survey 123 CSV Content in custom Javascript

949
3
11-30-2021 08:45 AM
XavierRouxRacine1
New Contributor

Hi everyone,

 

I have an issue with Survey123 about reading a Csv File in a custom javascript function. I would like to pass the CSV data content as an argument to a custom javascript function and get the sum for a field based on the value of 3 to 5 associated records. Here is the javascript function that I want to implement with arg1 as the content of my csv file.

 

 

function myfunction(arg1, arg2, arg3, arg4, arg5) {

 

// Add your code here

var superficie = []

for(var i = 0; i < arg1.length; i++) {

 

if(arg1[i].param1 == arg2) {

if(arg1[i].param2 >= arg3 & arg1[i].param4 <= arg4) {

 

superficie.push(arg1[i].param5)

 

}

 

}

 

}

var total_sup = 0;

for(var i = 0; i < superficie.length; i++) {

total_sup = total_sup + superficie[i]

}

return total_sup;

}

 

 

Thank you

0 Kudos
3 Replies
ZacharySutherby
Esri Regular Contributor

Hello @XavierRouxRacine1

One of the limitations of using JavaScript functions is the yare not able to access local files. If your publish your CSV as a hosted table in your ArcGIS organization you can query the table in the JS function to return a JSON response, and then work with that JSON response in your JavaScript function. 

Thank you,
Zach
0 Kudos
StaciDratler
New Contributor

Hi @ZacharySutherby ,

We are working on a form that uses javascript to pull previous data from a live feature service, however this function does not work when a form is offline. In the past we have simply used the pulldata function with a CSV file. Based on your statement above though, its sounds like we cannot merge the two processes. IE: Use Javascript to call on a CSV file in the media folder to pull previous values. 

Our plan was to download the dataset, put into the media folder as a CSV and run our javascript on that. The goal is to pull the previous three readings for a given location (water values) which has multiple entries for one location. Our Javascript runs through the locations and finds the previous three readings out of the 10 readings it actually has. We are able to do this on a live dataset, so If the CSV goes with the form and works offline with the pulldata, why would it not work with a pulldata @ javascript?

Thank you in advance. 

Staci

0 Kudos
lannguyentl
New Contributor III

Totally agree with Staci! Working offline with the same functionalities requires a lot of functions running at client side.

Also, MMPK is useful for offline, however, except for using it as a basemap, we cannot geoprocess it or extract data, extract locator from it. Should have a pulldata pulldata () with MMPK or something similar for Survey123. 

I did see people developing app in Qt can read the locator in MMPK loaded in a device, S123 should have the same capability.

 

Thanks,

Lan