Parsing value returned from RP.getParameterValue with a regular expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2015 07:19 AM
I am trying to pull a URL parameter into a Jelly UI page, and parse out all numeric and non-letter values.
For testing purposes; if I hard-code a string value, the regular expression works correctly. However if I try to parse the value pulled form RP.getParameterValue the script include, it fails at the regular expression line. It also fails if I include the regular expression within the UI page too. SN has their own built in regex API (SNC.Regex) which also can't process values pulled from RP.getParameterValue. I've tried converted the returned value to a string, with no luck either.
[code]
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate jelly="true">
var stringValue = "Support, Office 12345 ,,, Help Desktop"; // Works
//var stringValue = RP.getParameterValue('sysparm_search'); // Doesn't work
var siRegEx = new RegExString();
returnValue = siRegEx.convert(stringValue);
arrayResults = returnValue.split(',');
</g:evaluate>
<br/>Raw Values: ${stringValue}
<br/>Returned Values: ${returnValue}
<br/>Array Values:
<j:forEach items="${arrayResults}" var="jvar_value">
${jvar_value}
</j:forEach>
</j:jelly>
[/code]
[code]
var RegExString = Class.create();
RegExString.prototype = {
initialize: function() {
},
convert : function(string) {
string = string.toString();
gs.log('Debug string: ' + string);
if (string) {
newString = string.replace(/[^a-z]+/gi, ',');
gs.log('Debug newString: ' + newString)
return newString;
}
},
type: 'RegExString'
};
[/code]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2015 09:59 AM
Thank you Travis. Based on you replies; I have changed to your suggestion. Originally I tried string = string.toString(); but I didn't think of just adding a blank value to the string.