Hi, How I can store only number field in Free-Form...
# suitescript
l
Hi, How I can store only number field in Free-Form-Text field of custom record? My User event is storing in '2.0' always and I want to avoid that and only want to store number field value like '2', Can I set formula field? If yes then how?(I don't want to use Integer field for some reason) Anyone can help me?
s
Do you want the field to be free form ? If you make it as interger type only the number will be saved
l
No, I want to free form, no Integer
s
You mean you want to store only interger ? in the free form ?
l
Yes, correct
no any decimal
s
You can use a native javascript to do that !!
l
No man, Its not allowing in free form text field, I tried almost all JS.
s
Where are you getting the value for free form?
l
in Suitescript if you uses Free form text field and try to store integer it will always store as 1.0 no 1
I am getting value in one of my user event.
s
Share your code
k
Are you storing as a string?
l
No, I am converting it to number using parseInt
k
That is probably why. As freeform is just a string.
l
hmm, true but still any option?
k
Can you post your code where you are setting the value?
c
I think I have had this issue before. I was calling the toString method on the number before setting it in the field. If you just pass the number in, it should work.
k
My thoughts exactly!
c
I am not sure why, but in the debugger it shows 5.0 as a result of parseInt("5")🤔
l
@chriswebb let me check this..
var mynumber = '1.02'; var a = parseInt(mynumber); Math.round(a); Output: 1.0
Above code will always give you result in 1.0 formart
k
According to console it will give 1. But not sure on a script.
i think you need to change
a
back to a string.
l
Hmm, This works.. 😀
👍 1
Thanks you.
j
contributing late, but numbers in javascript are always floats if you want to represent a number with a certain amount of decimal places use the
toFixed
function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
e.g.
Copy code
var x = 1;
console.log(x.toFixed(0)); // 1
console.log(x.toFixed(2)); // 1.00
👍 1