STRING OR BINARY DATA WOULD BE TRUNCATED. THE STATEMENT HAS BEEN TERMINATED

734
2
Jump to solution
12-13-2021 02:36 AM
JavierCMartínezPrieto
Occasional Contributor

Hello,
I have created a survey in SURVEY123, and I get the following error: STRING OR BINARY DATA WOULD BE TRUNCATED. THE STATEMENT HAS BEEN TERMINATED. I have looked at the solutions that are uploaded to the forum and they have not worked, I have changed the length of the field, I have changed the type of this and I still get the same error.
my case is the following:
I have created a survey for vehicle monitoring and I have a field called initial kilometers.
I would like this field to be filled with the previous value that has been put, for this I have made a script in JavaScript (thanks Ismael Chivite for the help).

function getLastGeneratorReading(Parte_de_vehiculo,token){
    var xmlhttp = new XMLHttpRequest();
    var params = "/query?";
    params = params + "where=Parte_de_vehiculo='" + Parte_de_vehiculo + "'&outFields=KmIni"
    params = params + "&returnGeometry=false&orderByFields=OBJECTID DESC&resultRecordCount=1&f=json";
    if (token ){
    params = params + "&token=" + token ;
    }
    var url = featureLayer + params;
    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.KmIni);
    }
    else{
    return "";
    }
    }
    }
    }
   
   


This script works and shows me the value I want the problem comes when publishing the survey through the mobile device that gives me the failure mentioned above and does not allow me to send it.

thanks in advance to all of you who participate to get the solution.

Regards

En Español:

Hola,
he creado una encuesta en SURVEY123, y me da el siguiente error: STRING OR BINARY DATA WOULD BE TRUNCATED. THE STATEMENT HAS BEEN TERMINATED. he mirado las soluciones que están subida al foro y no me han funcionado, he cambiado la longitud del campo, he cambio el tipo de este y me sigue dando el mismo error.
mi caso es el siguiente:
he creado una encuesta para la supervisión de vehículos y poseo un campo que se llama kilómetros iniciales.
me gustaría que este campo se rellene con el valor anterior que se ha puesto, para ello se ha realizado un script en JavaScript (gracias Ismael Chivite por la ayuda).

function getLastGeneratorReading(Parte_de_vehiculo,token){
    var xmlhttp = new XMLHttpRequest();
    var params = "/query?";
    params = params + "where=Parte_de_vehiculo='" + Parte_de_vehiculo + "'&outFields=KmIni"
    params = params + "&returnGeometry=false&orderByFields=OBJECTID DESC&resultRecordCount=1&f=json";
    if (token ){
    params = params + "&token=" + token ;
    }
    var url = featureLayer + params;
    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.KmIni);
    }
    else{
    return "";
    }
    }
    }
    }
   


este script funciona y me muestra el valor que quiero el problema viene a la hora de publicar la encuesta a través del dispositivo móvil que me arroja el fallo mencionado con anterioridad y no me permite enviarla.

gracias de antemano a todos los que participéis para conseguir la solución.

Saludos

Javier C. Martinez Prieto
0 Kudos
2 Solutions

Accepted Solutions
by Anonymous User
Not applicable

Hi @JavierCMartínezPrieto,

It appears you are trying to return the entire JSON object from the JS function into a text input in the survey? Is that correct? If so how many characters on average is the JSON response, and how big did you make the fieldLength of the text input?

Regards,

Phil.

View solution in original post

0 Kudos
JavierCMartínezPrieto
Occasional Contributor

Good morning, I already discovered the error and it was not in that script but in the box where the token was generated that if it exceeded the maximum allowed length. thanks for answering

Javier C. Martinez Prieto

View solution in original post

2 Replies
by Anonymous User
Not applicable

Hi @JavierCMartínezPrieto,

It appears you are trying to return the entire JSON object from the JS function into a text input in the survey? Is that correct? If so how many characters on average is the JSON response, and how big did you make the fieldLength of the text input?

Regards,

Phil.

0 Kudos
JavierCMartínezPrieto
Occasional Contributor

Good morning, I already discovered the error and it was not in that script but in the box where the token was generated that if it exceeded the maximum allowed length. thanks for answering

Javier C. Martinez Prieto