Greetings all,
I have a JavaScript script for a survey in survey123, this script takes the maximum value of a field of the survey, but I need this maximum value to be filtered by another field of this survey.
The example is the following, I have a field with the kilometres that the vehicles have done and another field where the license plates are, when I run the script it gives me the maximum value in kilometres but I need that maximum value to be the one of a specific license plate and not the maximum of that field.
This would be the script (it is a small modification of one that is already uploaded on the web):
function getMax(IdCoche,token) {
var field = 'KmFin';
var params = "/query?";
params = params + "where=IdCoche='" + IdCoche + "'&outFields=KmFin"
params = params + "&orderByFields=KmFin ASC&resultRecordCount=KmFin&f=json"
params = '/query?where=1=1&outStatistics=[{"statisticType":"MAX","onStatisticField":"' + field + '","outStatisticFieldName":"MAX"}]&f=json';
var URL = fl + params;
var xmlhttp = new XMLHttpRequest();
if (token){
URL = URL + "&token=" + token;
}
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[0].attributes.MAX);
}
else{
return "No Features Found";
}
}
}
}
all help is welcome.
Greetings to all.
######################ESPAÑOL################################
Saludos a todos,
tengo un script de JavaScript para una encuesta en survey123, este script toma el valor máximo de un campo de la encuesta, pero necesitaría que este valor máximo se filtrara por otro campo de esta encuesta.
el ejemplo es el siguiente, tengo un campo con los kilómetros que han hecho los vehículos y otro campo donde están las matriculas, cuando ejecuto el script me da el valor máximo que hay en Kilómetros pero necesito que ese valor máximo sea el de una matricula especifica y no el máximo de ese campo.
este seria el script(es un pequeña modificación de una que ya esta subido en la web):
SCRIPT EN LA PARTE QUE ESTA EN INGLES
toda ayuda es bien recibida.
Saludos a todos.