- 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 07:34 AM
Hi,
If the field is of type "Integer" then system will truncate the leading zeros as integers do not have any leading zeros.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 08:05 AM
Thanks Saurabh for this enlightment.
I have another question, why the sort does not work ?
My goal is to copy number from a string field to an integer field so i can sort them (1, 2, 3... 100...200...etc).
But when i copy the value in the filed, the sort does not work.
And i notice that integer fields get their values on the right when my custom integer field get it on the left (like string).
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 08:07 AM
Hi,
Can you give the screenshot of both fields type from the dictionary.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:00 AM
Hi,
Here are the 2 fields :
String :
Integer :