How to ask the user for a value and insert it on a currency field

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…

Welcome to the community, @Nicolas_Hurtado! :smiley: 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)});
1 Like

Thanks for taking the time to answer and for the extra suggestion. I’m enjoying this learning process of scripting. :slight_smile:

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.