Help

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

Solved
Jump to Solution
1153 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Nicolas_Hurtado
5 - Automation Enthusiast
5 - Automation Enthusiast

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…

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

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)});

See Solution in Thread

2 Replies 2
Justin_Barrett
18 - Pluto
18 - Pluto

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)});

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