Copy Value from a string field into an integer field and add Zeros

Nico12
Mega Sage

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

Nico12_2-1694613999184.png

 

But in the field, it does not work.

 

 

Nico12_1-1694613929768.png

Any advices ?

 

Regards,

1 ACCEPTED SOLUTION

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.

View solution in original post

11 REPLIES 11

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.

Thanks asifnoor,

 

you are right, i tried to create a BR instead and it is working. 

 

Thanks guys!