Dec 28, 2021 02:20 PM
Hello dear community. First time asking a question and learning the basics of scripting.
One part of my script asks the user for a value like this:
let SessionPrice = await input.textAsync (‘Input price per coaching session’);
Then I’m trying to insert that value on a currency field with:
Let CreateField = await MainTable.createRecordsAsync([{Fields:{“UnitPrice”: SessionPrice}]);
And I get the error:
j: Can’t create records: invalid cell value for field ‘UnitPrc’.
Cell value has invalid format: must be a number
I guess its because its a ‘text’ string and I don’t know how to convert it or make it a ‘currency’.
In advances I’ll appreciate your help.
Thanks…
Solved! Go to Solution.
Dec 28, 2021 09:58 PM
Welcome to the community, @Nicolas_Hurtado! :grinning_face_with_big_eyes: It’s definitely a tad annoying that there isn’t a direct way to do numeric entry with a script. That aside, converting a string to a number is fairly simple: wrap the Number()
type around your string.
As a side note, you don’t need to assign the result of record creation to a variable (unless you need to use the new record ID somewhere else in your code). You can also use the createRecordAsync
(singular) variant because you’re only creating a single record, and simplify the data that you’re passing.
With those changes applied, your line looks like this:
await MainTable.createRecordAsync({"UnitPrice": Number(SessionPrice)});
Dec 28, 2021 09:58 PM
Welcome to the community, @Nicolas_Hurtado! :grinning_face_with_big_eyes: It’s definitely a tad annoying that there isn’t a direct way to do numeric entry with a script. That aside, converting a string to a number is fairly simple: wrap the Number()
type around your string.
As a side note, you don’t need to assign the result of record creation to a variable (unless you need to use the new record ID somewhere else in your code). You can also use the createRecordAsync
(singular) variant because you’re only creating a single record, and simplify the data that you’re passing.
With those changes applied, your line looks like this:
await MainTable.createRecordAsync({"UnitPrice": Number(SessionPrice)});
Dec 29, 2021 04:52 AM
Thanks for taking the time to answer and for the extra suggestion. I’m enjoying this learning process of scripting. :slightly_smiling_face: