A quick search in Google will find some SQL functions that strip the unwanted characters.
Might this suit your skillset better than using a Java plugin? From: Action Request System discussion list(ARSList) [mailto:arslist@ARSLIST.ORG] On Behalf Of Jeff Lockemy (QMX Support Services) Sent: 16 May 2012 21:25 To: arslist@ARSLIST.ORG Subject: Re: Cleaning Special Characters from a Character Field ** Thank you Axton! We'll give it a go. From: Action Request System discussion list(ARSList) [mailto:arslist@ARSLIST.ORG] On Behalf Of Axton Sent: Wednesday, May 16, 2012 4:01 PM To: arslist@ARSLIST.ORG Subject: Re: Cleaning Special Characters from a Character Field ** Here is a very simple Java plugin to get you started (38 lines of code). The plugin accepts 2 parameters; a regex and a value, and returns true/false on whether the string conforms to the regex. You can extend or modify this to perform a conversion instead of doing a comparison. import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import com.bmc.arsys.api.ARException; import com.bmc.arsys.api.Value; import com.bmc.arsys.pluginsvr.plugins.ARFilterAPIPlugin; import com.bmc.arsys.pluginsvr.plugins.ARPluginContext; public class Regex extends ARFilterAPIPlugin { /** * @param context ARPluginContext provided by the plugin server. * @param arg1 Input parameters: * 1 - Regular Expression conforming to java.util.regex * 2 - String to evaluate * @return Boolean, does the string conform to the regular expression * 0 - False * 1 - True * @see java.util.regex.Pattern * @exception ARException handled by plugin server * @since 1.0 */ public List<Value> filterAPICall(ARPluginContext context, List<Value> arg1) throws ARException { // Create List of Values to hold response List<Value> results = new ArrayList<Value>(); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "Regex Plugin Called with parameters:" + arg1.get(0).getValue()); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, " Pattern: " + arg1.get(0).getValue()); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, " Value: " + arg1.get(1).getValue()); // set up the pattern Pattern pattern = null; try { pattern = Pattern.compile(arg1.get(0).getValue().toString()); } catch (PatternSyntaxException e) { context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "PatternSyntaxException at " + e.getIndex()); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "Pattern: " + e.getPattern()); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "Description: " + e.getDescription()); context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "Message: " + e.getMessage()); throw e; } // set up the value Matcher value = pattern.matcher(arg1.get(1).getValue().toString()); // test the value against the pattern and get the result boolean b = value.matches(); int result = 0; if (b == false) result = 0; if (b == true) result = 1; context.logMessage(context.getPluginInfo(), com.bmc.arsys.pluginsvr.plugins.ARPluginContext.PLUGIN_LOG_LEVEL_INFO, " Result: " + result); results.add(new Value(result)); return results; } } On Wed, May 16, 2012 at 2:10 PM, Jeff Lockemy (QMX Support Services) <jlock...@gmail.com> wrote: ** Thanks for the input guys. In reference to Axton's suggestion - I'm certainly not a Java guy, but might be able to find some internal resources to tap into on that front. In the meantime, Jason's suggestion of a VB or batch file script might be good quick and dirty solution to buy us more time to implement something more elegant. Thanks again! Cheers, Jeff From: Action Request System discussion list(ARSList) [mailto:arslist@ARSLIST.ORG] On Behalf Of Jason Miller Sent: Wednesday, May 16, 2012 2:58 PM To: arslist@ARSLIST.ORG Subject: Re: Cleaning Special Characters from a Character Field ** I agree. I haven't had a chance to write a plugin yet but we have a few cases where we built DB functions or server side scripts (.vbs, .bat) that we call from a Filter using Direct SQL or Run Process. It isn't as elegant as what Axton describes but is more or less the same concept; off load the works to an external process on the server to do the work and give the result back to Remedy. Jason On Wed, May 16, 2012 at 11:41 AM, Axton <axton.gr...@gmail.com> wrote: ** I would not use client side technologies for data validation or sanitization; at some point someone or something will bypass it (api, web service, import, workflow, etc.). I wrote a Java plugin that uses the java regex capabilities to do something similar. It relatively simple to write and you can pass the regex parameters to the plugin; just figure out what you want to give to the plugin and what you want to get back, then fill in the blanks with the Java. http://docs.oracle.com/javase/tutorial/essential/regex/ http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html The following classes should have all you need: java.util.regex.Pattern java.util.regex.Matcher Axton Grams On Wed, May 16, 2012 at 11:49 AM, Jeff Lockemy (QMX Support Services) <jlock...@gmail.com> wrote: ** Good Day Listers, I've been going round and round on this and I hope that someone has some suggestions. I need to strip out special/non-standard characters in a character field before passing it to a web service. I was thinking that running some JavaScript when the user submits the contents via the Mid-Tier might be a decent approach. Not really knowing JavaScript, I dug around and found a "removeSpecialChars" function on the web that I was trying to adapt, but I haven't had much luck. Based on examples that I found on the ARSList and BMC Community, I put the function in the Web Footer Content of the form: <html> <script> function removeSpecialChars(strVal) { strVal = strVal.replace(/[^A-Za-z 0-9 \.,\?""!#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '') ; } </script> <body> </body> </html> Then I tried several different Active Link Run Process commands to run the function on submit or modify: javascript:window.F(536870913).S(removeSpecialChars($Character Field$)); javascript:window.F(536870913).S(new CharType(removeSpecialChars ("arid536870913").value)); However, when I submit or modify the field contents, I always get the following error: Caught exception: Object doesn't support property or method 'hasMessages' Now I'm wondering if JavaScript is really the best way to approach this. If JavaScript is a good approach, then can anyone see what I am doing wrong here? If it isn't, any suggestions of a better way? Thanks in advance. Respectfully, Jeff _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _attend WWRUG12 www.wwrug.com ARSlist: "Where the Answers Are"_ _______________________________________________________________________________ UNSUBSCRIBE or access ARSlist Archives at www.arslist.org attend wwrug12 www.wwrug12.com ARSList: "Where the Answers Are"