I wrote the regex plugin because I had a set of requirements that workflow
could not address.  We would get bad characters, and I needed to whitelist
the characters that could be used and where in the string they could be
used.  The Java regex capabilities were a good fit.  They let you look
for occurrence counts, use anchors, etc.  In my case, I needed to whitelist
the characters that were allowed in the string.  I could not conceive a way
of doing this in workflow, short of pulling evaluating each character in
the string individually.  This was inefficient and difficult to maintain,
so I opted for the plugin.

I started finding that there were many things I could do with the regex
capabilities that workflow is just a pain in the rear to do.  For example,
if I want to allow phone numbers on one of several formats, or I want IP
addresses to be valid and not have leading zeroes in the octets, or I want
a valid email address format.  For example:

Email
Address: 
^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
IP
Address: 
^([01]?\d\d?|2[0-4]\\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$
Letters a to z, A to Z, 0 to 9, (comma), and (dash) are
allowed: ^[a-zA-Z0-9-,/\\]+$
Letters a to z, A to Z, 0 to 9, space, and - are allowed but space is not
allowed at the beginning or end of the string: ^[^ ][a-z A-Z0-9-]+[^ ]$

Just to name a few.  The way I wrapped the plugin, I have a repository of
evaluations I can perform and I can reuse those wherever they are needed,
and I can modify the evaluation and it is instantly used in all places that
need to use that evaluation.  In workflow, this would be problematic to
maintain because it would mean modifying workflow in many places to account
for a single evaluation I was doing in many places.  It means finding all
the places, making sure the workflow is modified properly, and that is just
time consuming and the next poor sap who comes along doesn't have much of a
chance of getting it right.

Along this train of thought, it would be nice if I could define the pattern
in the field properties, similar to the way $MENU$ works, but instead of
using the menu for validation, use the regex from the repository.  If that
were the case, there would be no workflow to write to validate input, just
define and reuse the regex.

Axton Grams

On Thu, May 17, 2012 at 3:24 AM, Misi Mladoniczky <[email protected]> wrote:

> Hi,
>
> You can do this with normal filters as well, even if it will be a little
> bit slower.
>
> I like the Service functionality, and would create a simple
> Display-only-form with two fields Dirty and Clean and two filters:
>
> FLTR 1:
>  Run If: ('Dirty' LIKE "[A-Za-z 0-9.,\?""!#$%^&*()_=+/;:<>|}{[`~-]%" OR
> 'Dirty' LIKE "]%")
>  Set-Fields: Clean = $Clean$ + LEFTC($Dirty$, 1)
>
> FLTR 2:
>  Run If: ('Dirty' LIKE "_%")
>  Set-Fields: Dirty = SUBSTRC($Dirty$, 1)
>  Goto: 1
>
> Just call your Service with Dirty as input and Clean as output.
>
>        Best Regards - Misi, RRR AB, http://www.rrr.se (ARSList MVP 2011)
>
> Products from RRR Scandinavia (Best R.O.I. Award at WWRUG10/11):
> * RRR|License - Not enough Remedy licenses? Save money by optimizing.
> * RRR|Log - Performance issues or elusive bugs? Analyze your Remedy logs.
> Find these products, and many free tools and utilities, at http://rrr.se.
>
> > Thank you Axton!  We'll give it a go.
> >
> >
> >
> > From: Action Request System discussion list(ARSList)
> > [mailto:[email protected]] On Behalf Of Axton
> > Sent: Wednesday, May 16, 2012 4:01 PM
> > To: [email protected]
> > 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)
> > <[email protected]> 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:[email protected]] On Behalf Of Jason Miller
> > Sent: Wednesday, May 16, 2012 2:58 PM
> > To: [email protected]
> > 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 <[email protected]> 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)
> > <[email protected]> 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"_
> >
> >
> >
> _______________________________________________________________________________
> > UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
> > attend wwrug12 www.wwrug12.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"
>

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
attend wwrug12 www.wwrug12.com ARSList: "Where the Answers Are"

Reply via email to