[Bps-public-commit] RT-Extension-ExtractCustomFieldValues branch, value-separator, created. 3.15-1-g8333561

? sunnavy sunnavy at bestpractical.com
Wed Jul 29 18:06:18 EDT 2020


The branch, value-separator has been created
        at  8333561e531cfa1648231f10ae699db5b6735709 (commit)

- Log -----------------------------------------------------------------
commit 8333561e531cfa1648231f10ae699db5b6735709
Author: Jeff Voskamp <jeff at voskamp.ca>
Date:   Tue Jun 9 13:21:36 2020 -0400

    Adding ValueSeparator support to customize separator for values

diff --git a/README b/README
index 7d9916b..85e579c 100644
--- a/README
+++ b/README
@@ -96,6 +96,15 @@ USAGE
     Changing the separator may be necessary, if you want to use a "|" in one
     of the patterns in the controlling lines.
 
+  ValueSeparator
+    You can change the separator string for multi-value customfields
+    (initially ",") in the template with:
+
+            ValueSeparator=<anyregexp>
+
+    Changing the mult-value separator may be necessary since your source may
+    use a list of values separated by spaces or ', ' or ';' etc.
+
   Examples
     For reference, a template with these examples is also installed during
     make initdb. See the CustomFieldScannerExample template for examples and
diff --git a/lib/RT/Action/ExtractCustomFieldValues.pm b/lib/RT/Action/ExtractCustomFieldValues.pm
index 47d4af4..a4321b8 100644
--- a/lib/RT/Action/ExtractCustomFieldValues.pm
+++ b/lib/RT/Action/ExtractCustomFieldValues.pm
@@ -41,6 +41,7 @@ sub TemplateConfig {
     }
 
     my $Separator = '\|';
+    my $ValueSeparator = ',';
     my @lines = split( /[\n\r]+/, $content);
     my @results;
     for (@lines) {
@@ -53,10 +54,15 @@ sub TemplateConfig {
             $Separator = $1;
             next;
         }
+        if (/^ValueSeparator=(.+)$/) {
+            $ValueSeparator = $1;
+            next;
+        }
         my %line;
         @line{qw/CFName Field Match PostEdit Options/}
             = split(/$Separator/);
         $_ = '' for grep !defined, values %line;
+        $line{ValueSeparator} = $ValueSeparator;
         push @results, \%line;
     }
     return \@results;
@@ -220,7 +226,7 @@ sub ProcessCF {
     if ( $args{CustomField}->SingleValue() ) {
         push @values, $args{Value};
     } else {
-        @values = split( ',', $args{Value} );
+        @values = split( /$args{ValueSeparator}/, $args{Value} );
     }
 
     foreach my $value ( grep defined && length, @values ) {
diff --git a/lib/RT/Extension/ExtractCustomFieldValues.pm b/lib/RT/Extension/ExtractCustomFieldValues.pm
index 8ce1c4d..228cb48 100644
--- a/lib/RT/Extension/ExtractCustomFieldValues.pm
+++ b/lib/RT/Extension/ExtractCustomFieldValues.pm
@@ -134,6 +134,16 @@ template with:
 Changing the separator may be necessary, if you want to use a "|" in
 one of the patterns in the controlling lines.
 
+=head2 ValueSeparator
+
+You can change the separator string for multi-value customfields (initially
+",") in the template with:
+
+        ValueSeparator=<anyregexp>
+
+Changing the mult-value separator may be necessary since your source may
+use a list of values separated by spaces or ', ' or ';' etc.
+
 =head2 Examples
 
 For reference, a template with these examples is also installed during

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list