Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Convert Single Line Text variable to Integer

Joe Taylor
Giga Guru

I have a Single Line Text Variable called "Base_Salary".

I'm using a Regular Expression validation to make sure the format matches $000,000  ($ sign and comma are mandatory)

Now I want to take this string and replace the $ sign and comma with "", then convert this resulting string to an integer.

The reason is I'd like to setup a condition in my workflow that branches my approvals based on this integer value.

(See attachment)

What's the best way to handle this?

Thanks.

 

Joe

 

1 ACCEPTED SOLUTION

Can you try below.

var oldvalue = current.variables.base_salary.toString();
var newvalue = oldvalue.toString().replace(/\$/g,''); //adding both in same will not work. replaces $
newvalue=newvalue.toString().replace(/\,/g,''); //replaces comma
var value = parseInt(newvalue);

View solution in original post

6 REPLIES 6

Can you try below.

var oldvalue = current.variables.base_salary.toString();
var newvalue = oldvalue.toString().replace(/\$/g,''); //adding both in same will not work. replaces $
newvalue=newvalue.toString().replace(/\,/g,''); //replaces comma
var value = parseInt(newvalue);

Joe Taylor
Giga Guru

Yay!  This worked great Jaspal!

The string variable is being converted to an integer properly.

My workflow condition is now branching the way I want.

 

Hopefully this post will help others with a similar requirement.

 

Thanks.

 

Joe