Hi, John.
I’m trying to run a Custom JavaScript, but it doesn’t work. When we are in the piece of code the bot doesn’t do anything. Below I send you our code we are using.
CODE:
var rut = {{pregunta_rut_clave.parsed_answer}}
var valor = rut.split(’.’).join("");
valor = valor.split(’-’).join("");
cuerpo = valor.slice(0, -1);
dv = valor.slice(-1).toUpperCase();
rut = cuerpo + ‘-’ + dv;
if (cuerpo.length < 7) {
return reject("No es valido el Rut");
}
suma = 0;
multiplo = 2;
for (i = 1; i <= cuerpo.length; i++) {
index = multiplo * valor.charAt(cuerpo.length - i);
suma = suma + index;
if (multiplo < 7) {
multiplo = multiplo + 1;
} else {
multiplo = 2;
}
}
dvEsperado = 11 - (suma % 11);
dv = (dv == 'K') ? 10 : dv;
dv = (dv == 0) ? 11 : dv;
if(dvEsperado == dv) {
return resolve("Es valido el rut")
} else {
return reject("No es valido el Rut);
}
Thanks in advance.