How to properly set integer value?

AndresGT1
Giga Expert

Hello,

I'm working on some values that are calculated with a ScriptInclude through a ClientScript with GlideAjax, but the returning value comes with a ".0" and it won't let me submit.

How do I take that part away?

You can see that the ".0" in "Horas Desarrollo" and "Horas OLC" aren't letting me submit the form and a message appears "Integer not valid"

find_real_file.png

This is my CLIENT SCRIPT

var monto = g_form.getIntValue('u_dmn_presupuesto_desarrollo_v2');

var ga = new GlideAjax('CalcularHoras');

ga.addParam('sysparm_name', 'horasDesarrollo');

ga.addParam('sysparm_monto', monto);

ga.getXML(Calculo);

function Calculo(response){

var answer = response.responseXML.documentElement.getAttribute('answer');

g_form.setValue('u_dmn_horas_desarrollo', answer);

}

This is the SCRIPT INCLUDE FUNCTION

horasDesarrollo : function(){

var total;

var presupuesto = this.getParameter('sysparm_monto');

var gd = new GlideDate();

var gr = new GlideRecord('u_tarifas_horas');

gr.addQuery('u_ano', gd.getYearNoTZ());

gr.addQuery('u_tipo_de_tarifa', 'desarrollo');

gr.query();

gr.next();

total = presupuesto/gr.u_tarifa;

total = Math.round(total);

return total;

}

1 ACCEPTED SOLUTION

Did you try this:


  1. function Calculo(response){  
  2. var answer = response.responseXML.documentElement.getAttribute('answer');  
  3. g_form.setValue('u_dmn_horas_desarrollo', parseInt(answer));  
  4. }


in your client script?



I want to refer to this for additional information: parseInt() - JavaScript | MDN


For your understanding: This was only a test, you have to set the 2nd parameter (in this case, '10' would be the correct one). Just read the article 😃


View solution in original post

6 REPLIES 6

AndresGT1
Giga Expert

I've tried turning it into a string, splitting it and then slice it to obtain only the number, then parse it again into number, but it keeps returning the number with a ".0".



I might be passing by something obvious, but can't realize what it is.


danielschmidt
Kilo Expert

Hi,



integer is a a number format in programming languaes that doesn't support floating points. so, you need to get an integer from your script include or try to code a parseInt() before you write the value in your box.


Did you test it without the ".0"?



Could you provide the code you're using already?


Updated the post with the current codes I'm using.


I've tried using parseInt before the return but didn't work.


Bryan Tay3
Mega Guru

hi Andres,



what are the field type of "Horas Desarrollo"?