- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 03:57 AM
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
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.
I don't know if anyone has ever had the same thing happen to them and how they have been able to solve it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2023 11:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2023 11:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 04:37 AM
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.