Help

Welcome to the Airtable Community! If you're new here, check out our Getting Started area to get the most out of your community experience.

Help on Script with Math Function

Topic Labels: Scripting extentions
500 3
cancel
Showing results for 
Search instead for 
Did you mean: 

Any idea why the math isn’t working in my script. I am expecting two numbers to be added together (2+20018 = 20020) but instead get 220018

let table = base.getTable(‘Project List’);
let queryResult = await table.selectRecordsAsync();
let record = queryResult.getRecord(queryResult.recordIds[0]);
console.log(record)
let year = record.getCellValue(‘Year Count’)
console.log(year)
let num = year+20018
await table.updateRecordAsync(record.id, {“Project #”: num})

3 Replies 3

Wild guess - you’re concatenating at least one string plus a number and JavaScript is converting it all to a string.

Try using parseInt() on each value to ensure they are numbers.

That worked (BTW I know nothing of JS, I am just learning from reading the API documentation).

Now you now more than nothing. :winking_face: