- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 07:08 AM
Hi,
I am trying to copy value from a string field to an integer field (both are on the same table).
Script (calculated field)
(function calculatedFieldValue(current) {
// Add your code here current.u_poste_commande_achat_classement
var number = current.u_poste_commande_achat;
gs.log("Avant : " + number);
if(number < 100){
//number = number.toString().padStart(3, '0');
number = ("0" + number).slice(-3);
}
gs.log("Après : " + number);
return number; // return the calculated value
})(current);
In the log it appears correctly with the 0 add to 30
But in the field, it does not work.
Any advices ?
Regards,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 03:24 AM
I am not fully sure but i think that the calculated field does not store the value in the database, It does calculation on the fly and dispalys. When you use sort, it work works on the underlying database values and not the calculated ones.
Mark the comment as a correct answer and helpful if this has helped to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:05 AM
Hi,
Your custom field is string type.
Sorting in string works in a different way.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:25 AM
Well that's all my problem here.
I have a custom field that is string type and another custom field that is integer type.
I need to copy the value from the string field to the integer field and transform it in integer so i can sort the values correctly.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:28 AM - edited 09-13-2023 11:37 AM
Hi,
You can copy the string field to integer field and apply the sorting on integer one.
Also use the radix as well parseInt(0090,10)==90.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 02:23 AM
Well my problem is that it does not working. The integer field does not behave like it should.
The sorting is wrong :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 02:58 AM
Hi,
Can you please share the screenshot of string field as well.
Thanks and Regards,
Saurabh Gupta