Help with JavaScript Script for Survey123
Good morning, everyone.
I need help with a JavaScript script for Survey123.
This is the script:
function getLastGeneratorReading(Parte_de_vehiculo,token){
var featureLayer = "https:\\services3.arcgis.com\dha0QtUTrPxlyZDZ\arcgis\rest\services\service_fcedea123ecd4de38c63d01eae3f53c0\FeatureServer\0";
var xmlhttp = new XMLHttpRequest();
var params = "/query?";
params = params + "where=Parte_de_vehiculo=+" + Parte_de_vehiculo + "'&outFields=KmFin"
params = params + "&returnGeometry=false&orderByFields=IdCoches DESC&resultRecordCount=1&f=json";
if (token ){
params = params + "&token=" + token ;
}
var url = featureLayer + params;
xmlhttp.open("GET",url,false);
xmlhttp.send(); /*peticion asincornica*/
if (xmlhttp.status!==200){ /*peticion sincronica*/ /*provoca error debido: porque te bloquearía el hilo dejando el cliente bloqueado hasta que se resolviese la petición*/
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.KmFin);
}
else{
return "";
}
}
}
}
currently it does not crash inside survey123 but it does not perform the function it is designed for.
the operation is basic, it should take the value of the last record that has been entered by a survey in survey123 in a row of a given field.
the value it currently gives is 0. This value is incorrect as it should give me as a result the last value that was sent by the survey.
Thanks in advance to all of you who participate.
Greetings Javier
Update:
value 0 is obtained return (xmlhttp.status); from what I have read it is a problem that it is not able to connect to the web page. would anyone know how to fix this error?
##########En Español#####################################################################
Buenas a todos.
Necesito ayuda con un script de JavaScript para Survey123.
Este es el Script:
function getLastGeneratorReading(Parte_de_vehiculo,token){
var featureLayer = "https:\\services3.arcgis.com\dha0QtUTrPxlyZDZ\arcgis\rest\services\service_fcedea123ecd4de38c63d01eae3f53c0\FeatureServer\0";
var xmlhttp = new XMLHttpRequest();
var params = "/query?";
params = params + "where=Parte_de_vehiculo=+" + Parte_de_vehiculo + "'&outFields=KmFin"
params = params + "&returnGeometry=false&orderByFields=IdCoches DESC&resultRecordCount=1&f=json";
if (token ){
params = params + "&token=" + token ;
}
var url = featureLayer + params;
xmlhttp.open("GET",url,false);
xmlhttp.send(); /*peticion asincornica*/
if (xmlhttp.status!==200){ /*peticion sincronica*/ /*provoca error debido: porque te bloquearía el hilo dejando el cliente bloqueado hasta que se resolviese la petición*/
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.KmFin);
}
else{
return "";
}
}
}
}
actualmente no da fallo dentro de survey123 pero no realiza la función para la que se ha diseñado.
el funcionamiento es básico, debería tomar el valor del ultimo registro que se ha introducido mediante una encuesta en survey123 en una fila de un campo determinado.
el valor que da actualmente es 0. Este valor es incorrecto ya que me debería dar como resultado el ultimo valor que se envió por la encuesta.
Gracias de antemano a todos lo que participéis.
Saludos Javier
Actualización:
el valor 0 se obtiene return (xmlhttp.status); por lo que he leído es un problema de que no es capaz de conectar con la pagina web. ¿alguien sabría como solucionar este error?