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

The field Type is Integer.



Don't know whats wrong with the return value, I'll update the post and put the code I'm using.


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 😃