- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 01:00 PM
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"
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:10 PM
Did you try this:
- function Calculo(response){
- var answer = response.responseXML.documentElement.getAttribute('answer');
- g_form.setValue('u_dmn_horas_desarrollo', parseInt(answer));
- }
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 😃
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:02 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:10 PM
Updated the post with the current codes I'm using.
I've tried using parseInt before the return but didn't work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:02 PM
hi Andres,
what are the field type of "Horas Desarrollo"?