substring() not working in record producer script

tarungupta1017
Kilo Contributor

Hi,

I am trying to use substring() function to extract a part of the variable value and pass it on the target record but it is not working. Actually, I want to remove the '$' sign from the value and take the rest of the string. I am able to pull the whole value but not a substring. Have tested by logging results in gs.log.

Can anyone please help?

Any help will be highly appreciated.

1 ACCEPTED SOLUTION

Just go with:

var capexSwCost = (producer.Software_CapEx_Cost.toString()).replace("$", "");

View solution in original post

10 REPLIES 10

Jim Coyne
Kilo Patron

How about using the replace() method instead?

str = "$123.45";
str2 = str.replace("$", "");

would return "123.45"

Otherwise, what are you trying now, and what are the results?

Community Alums
Not applicable

Could you please share your code, what exactly you are trying to do?

Here is the code - 

 

var CapexSwCost = producer.Software_CapEx_Cost;
var CapexSwCost1 = CapexSwCost.toString();
gs.log('CapEx SW Cost from RP in local substring var is ' + CapexSwCost1.substring(1)); // this line is showing the result as 'undefined'
gs.log('CapEx SW Cost from RP in local var is ' + CapexSwCost);
gs.log('CapEx SW Cost from RP in RP var is ' + producer.Software_CapEx_Cost);

gregmelmoth
ServiceNow Employee
ServiceNow Employee

Is the variable you are calling the substring() Method on of type string?

Maybe try variable.toString() prior to calling substring() if it is not