Post

2 followers Follow
0
Avatar

Should .startsWith method be working for string calculations?

I tried to find out if a string field starts with a certain number. I tried with the .startsWith Method, but didn't get it to work.

 

var inactive = @Status
var noprog = '2'
var change = '4'
var lost = '9'

if (inactive.startsWith(noprog)) {1}
else if (inactive.startsWith(change)) {1}
else if (inactive.startsWith(lost)) {1}
else {0}

Result is: "TypeError: undefined is not a function"

 

Dirk Spannaus

Please sign in to leave a comment.

2 comments

1
Avatar

Hi Dirk,

".startsWith()" was introduced with the JavaScript version ECMAScript 6, but Podio calc fields are using ECMAScript 5 - so this method isn't available in Podio (= undefined function).

But you can use .charAt(0) instead

inactive.chartAt(0) == noprog  || inactive.chartAt(0) == change || inactive.chartAt(0) == lost ? 1 : 0;

Rainer

Rainer Grabowski 1 vote