Help

Help on Script with Math Function

Topic Labels: Scripting extentions
1592 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Andrew
7 - App Architect
7 - App Architect

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.

Michael_Andrew
7 - App Architect
7 - App Architect

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: