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.

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

I have tried converting the variable value to string as well. Still it is not working.

 

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);

Just go with:

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

It worked, but, I am still surprised why substring() was not working

Community Alums
Not applicable
Hi, You are not giving all the parameters in substring. substring(startofstring, lengthofstring) Substring(2,5)

End of string is not a mandatory parameter. I need the full string from 2nd character.