Adding information to an Integer field from a transform map

fidel_ey
Tera Guru

Hello community.
I have two problems that I would like to consult with everyone. I am making a Transform map with a transform script and everything works fine except for four of the fields. Two of the fields have to add the data to two Integer fields, but the data you take from an excel document, are figures but when the figure are in thousands for example 6235 can be reflected as 6,235 or 6,235. I have tried to parse these fields to Float, Integer or String but I do not pass the data, there are times that only adds me a 6 as the complete data is not recognized but in the logs I see the full number, I have made functions to remove the points and commas, but when I do a target or a setValue() I get the same thing.
Script  - On Before

    var project_hhp = source.u_tps;
    var project_hhpTam = source.u_tps_tam;

            gr.setValue('u_field_table', project_hhp );
            gr.setValue('u_field_table'2, project_hhpTam );


In the same way it happens with a field that is a percentage, the data is added to a decimal field but it only adds the complete data and sometimes it does it with the point. In the same way I have made functions to handle this data like removing the % or having two decimals, but it doesn't work.

    var project1 = source.u_tam;
    var project2 = source.u_mix;

    project1 = parseFloat(project1.replace('%''').trim());
    project2 = parseFloat(project2.replace('%''').trim());
    project1= parseFloat(project1.toFixed(2));
    project2= parseFloat(project2.toFixed(2));


I don't know if anyone has ever had the same thing happen to them and how they have been able to solve it.

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

Hi @fidel_ey ,

Use below code first try to remove commas and percentage signs and replace with decimal values like below

project1 = project1.replace(',', '').replace('%', '').replace(/\./g, '').replace(',', '.');
project2 = project2.replace(',', '').replace('%', '').replace(/\./g, '').replace(',', '.');
project1 = parseFloat(project1);
project2 = parseFloat(project2);
project1 = parseFloat(project1.toFixed(2));
project2 = parseFloat(project2.toFixed(2));
gr.setValue('u_field_table', Math.round(project1));
gr.setValue('u_field_table2', Math.round(project2));

Please mark it as Solution Proposed and Helpful if it works for you.
Thanks,

Anand

View solution in original post

2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

Hi @fidel_ey ,

Use below code first try to remove commas and percentage signs and replace with decimal values like below

project1 = project1.replace(',', '').replace('%', '').replace(/\./g, '').replace(',', '.');
project2 = project2.replace(',', '').replace('%', '').replace(/\./g, '').replace(',', '.');
project1 = parseFloat(project1);
project2 = parseFloat(project2);
project1 = parseFloat(project1.toFixed(2));
project2 = parseFloat(project2.toFixed(2));
gr.setValue('u_field_table', Math.round(project1));
gr.setValue('u_field_table2', Math.round(project2));

Please mark it as Solution Proposed and Helpful if it works for you.
Thanks,

Anand

Hi Anand.
Thank you for your response. I wanted to comment that it works halfway, for the fields with several data if it is picking it up well, the problem I still have with the percentages, they continue to appear with the whole number. I have put exactly the same as you have indicated but it only takes as a whole number. The field where this data is added, the percentage, is a decimal field.