Post

2 followers Follow
0
Avatar

Converting String to Integer then Subtracting from Interger

Hello, 

 

I am attempting to make a calculation that will remove a prefix from our Unique_id ("F0") and attempting to subtract it by a number so that I can create a "Row Index" for our projects that we will use to batch out the projects using this field. I am running into difficulty with the calculation due to the ID being a string in order to remove the index. 

 

My current calculation is:

var id = @Unique ID.toString();
id.replace(/F0/g,"");

var num = (Number(id) - 18947);

num;

 

The replace works fine and removes the string, but the number portion never comes up. It only shows the same number with the string removed but the subtraction portion never activates. Any insight on what the issue could be? I know it is fairly difficult to make a string an integer, but in this case it should be converting to a number to run the calc off of it. 

 

 

LeRoy Reynolds

Please sign in to leave a comment.

1 comment

0
Avatar

Hello LeRoy,

first: you don't need to parse the unique id to string - the unique id is always a string (even if it contains digits only).

The "not a valid number" issue is caused by the calculation field sandbox view produces the preview. Under certain circumstances the sandbox expects that a string is returned even if you have parsed the string to a number (it's a bit more complex). 
You need to "persuade" Podio to accept the result as a number. This can be done by adding || 0 (read as: else 0) behind the result (instead of 0 you can use any number). That convinces Podio to accept the result as a number. 

var id = @Unique ID.replace(/F0/g,"");
var num = Number(id) || 0;
num - 18947

Rainer

Rainer Grabowski 0 votes
Comment actions Permalink