Converting string to number in script

Topic Labels: Scripting extentions
2443 3
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Hello! I am new to scripting. I am trying to replicate the action that is being performed on the variable below:

“ :writing_hand: CREATE: Product Input”: [{id:${inputConfig.productInputName[i]}}],


“ :writing_hand: ADD: Input Qty (Mass per Unit)”: [{id:${inputConfig.InputQty[i]}}]

But failing, I believe because InputQty is a string of numbers (but formatted as a string) and the receiving field is a number field. What is the best way to convert from string to number?

Screen Shot 2022-10-22 at 2.57.07 PM

3 Replies 3

Welcome to the Airtable community!

You can try parseInt() to convert a text string that looks like a number to a number.

But that might not be your issue. It looks like you are using the write format for a linked record field, not for a number field. To write to a number field, you just give the number, without the square brackets, curly braces, I’d, etc.

Your screen capture does not show the value for InputQty. The value is collapsed in the top right panel. The console.log() of the three records to create is also collapsed.

4 - Data Explorer
4 - Data Explorer

Thanks so much!! I updated the format per your suggestion and it looks like we are moving in the right direction, but I am still getting an error and also looks like there are 9 objects being written in the console log (should just be 3 numbers, as you can see – rest are undefined). Any idea what might be going wrong?

Screen Shot 2022-10-23 at 11.09.35 AM
Screen Shot 2022-10-23 at 11.15.17 AM

What is your level of experience writing code and what is your level of interest in learning to code?

It sounds like there are multiple issues going on here.

  • there is still an error in the field value, but this is for a different field
  • the script wants to create more records than you expect.

The issue with the field type not matching the value you provided depends on the actual field type. You can find the write formats for each field type in the scripting reference.

The issue with creating more records than you want is trickier because it isn’t clear how you are getting the quantity. It looks like the length of the productInput, but it isn’t clear how that value is set or what it is. Plus, the screen isn’t good at displaying nulls.