
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:27 AM
I'm trying to process a regex replace in a script include. The code will work in a background script, but fails in a script include.
regex: function(input) {
gs.info('input= '+input);
var cleaned = input.toString().replace(/[-+()\s]/g, '');
gs.info('A= ');
return cleaned;
the first gs.info will run, I never get anything from the second. What am I doing wrong?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 11:35 AM
A co-worker who is a much better developer than I found the issue. Apparently AJAX does not bring over the input as a true javascript string. I did see another post where someone mentioned the same thing, but that post didn't have a good way to correct it. The following line corrects the issue:
var stringInput = new String(input);
The script window complains about using String as a constructor, but it does fix the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:44 AM
Try the following:
regexCustom: function(input) {
gs.info('input= '+input);
var cleaned = input.toString().replace(/[-+()\s]/g,"");
gs.info('A= ');
return cleaned;
The name of your function may be colliding with OOB scripts as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:46 AM
Yea, that is a good point. Just changed it and tried again.....no change unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:49 AM
replace gs.info('A= ');
with
gs.info('A = ' + cleaned);
my br is:
(function executeRule(current, previous /*null when async*/) {
var s = current.short_description;
gs.log('test1 short desc ' + s);
//gs.print(regex('a-b'));
var sReplace = regex(s);
gs.log('test1 after ' + sReplace);
current.setValue('short_description', sReplace);
function regex(input){
gs.log('test1 input= '+input);
var cleaned = input.toString().replace(/[-+()\s]/g, '');
gs.log('test1 A= ' + cleaned);
return cleaned;
}
//var a = new ArrayUtil();
//a.push('a');
//gs.log('mal1 ' + a);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:53 AM
Well the problem with that is it has nothing to do with the function of the script. My issue is that that particular gs.info is not being processed, not that it's not containing the value of my variable.