- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 12:16 PM
Hi Everyone,
I am using SNow Jakarta instance & I am not able to remove '$' from my JSON string. Below is my code snippet:
var response = request.execute();
var getIdeationData = response.getBody();
var reg1 = new SNC.Regex('/u_number/');
getIdeationData = reg1.replaceAll(getIdeationData,'u_trading_partner_id');
getIdeationData.replace(/$/g,'');
PS: getIdeationData is my JSON string having key-value paired data.
In above code, Line 3 & 4 is working as expected. It is successfully replacing all occurrences of u_number with u_trading_partner_id.
But its not removing $. Till now I have tried below options to perform this task but hard luck...
getIdeationData.replace(/\$/g,'');
getIdeationData.replaceAll(/$/g,'');
getIdeationData.replace(/[$]/g,'');
getIdeationData.replace(/[\$]/g,'');
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 01:48 PM
have you tried toString() ? like:
getIdeationData.toString().replace(/\$/g,'');
if not try creating another SNC.Regex() object for the $ and use .replace()
http://wiki.servicenow.com/index.php?title=Using_Regular_Expressions_in_Scripts#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 01:48 PM
have you tried toString() ? like:
getIdeationData.toString().replace(/\$/g,'');
if not try creating another SNC.Regex() object for the $ and use .replace()
http://wiki.servicenow.com/index.php?title=Using_Regular_Expressions_in_Scripts#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 01:53 PM
I just tested this and it worked for me:
var myReg = "hey there $ sign".replace(new RegExp("\\$","gm"),"Dollar");
so try..
getIdeationData.toString().replace(new RegExp("\\$","gm"),"");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:36 PM
Thanks Nate,
I tried this and it worked for me.
var reg3 = new SNC.Regex(/\$/);
getIdeationData = reg3.replaceAll(getIdeationData,'');