<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Othomas</id>
	<title>Request Tracker Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Othomas"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/wiki/Special:Contributions/Othomas"/>
	<updated>2026-08-22T08:34:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=ImportCustomFieldValues&amp;diff=26315</id>
		<title>ImportCustomFieldValues</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=ImportCustomFieldValues&amp;diff=26315"/>
		<updated>2016-08-06T16:15:18Z</updated>

		<summary type="html">&lt;p&gt;Othomas: /* import-custom-field-values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==import-custom-field-values==&lt;br /&gt;
&lt;br /&gt;
I use this script to populate a &amp;quot;select one from many&amp;quot; custom field from a text file generated from a database query.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;   #!/usr/bin/perl&lt;br /&gt;
   &lt;br /&gt;
   use warnings;&lt;br /&gt;
   use strict;&lt;br /&gt;
   &lt;br /&gt;
   use lib qw(/opt/rt3/local/lib /opt/rt3/lib);&lt;br /&gt;
   use Getopt::Long;&lt;br /&gt;
   &lt;br /&gt;
   use RT;&lt;br /&gt;
   RT::LoadConfig();&lt;br /&gt;
   RT::Init();&lt;br /&gt;
   &lt;br /&gt;
   my %args;&lt;br /&gt;
   &lt;br /&gt;
   GetOptions(\%args, &#039;field=s&#039;, &#039;update&#039;,&#039;replace&#039; ,&#039;help&#039;, &#039;verbose&#039;);&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
    if ($args{&#039;help&#039;} || !($args{&#039;update&#039;}||$args{&#039;replace&#039;})  ){&lt;br /&gt;
      help();&lt;br /&gt;
      exit;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
   my @lines = &amp;amp;lt;STDIN&amp;amp;gt;;&lt;br /&gt;
   &lt;br /&gt;
   map {chomp} @lines;&lt;br /&gt;
   &lt;br /&gt;
   my $cf = RT::CustomField-&amp;amp;gt;new(RT-&amp;amp;gt;SystemUser);&lt;br /&gt;
   &lt;br /&gt;
   $cf-&amp;amp;gt;Load( $args{&#039;field&#039;} );&lt;br /&gt;
   unless ( $cf-&amp;amp;gt;id ) {&lt;br /&gt;
      die &amp;quot;Couldn&#039;t find that custom field\n&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   if ( $args{&#039;replace&#039;} ) {&lt;br /&gt;
      my $values = $cf-&amp;amp;gt;Values;&lt;br /&gt;
      my %map;&lt;br /&gt;
   &lt;br /&gt;
      while ( my $value = $values-&amp;amp;gt;Next ) {&lt;br /&gt;
          unless (grep {$value-&amp;amp;gt;Name} @lines) {&lt;br /&gt;
           print STDERR &amp;quot;Deleting &amp;quot; . $value-&amp;amp;gt;Name . &amp;quot;\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
              $value-&amp;amp;gt;Delete();&lt;br /&gt;
          }&lt;br /&gt;
   &lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   if ( $args{&#039;update&#039;} || $args{&#039;replace&#039;} ) {&lt;br /&gt;
      my $values = $cf-&amp;amp;gt;Values;&lt;br /&gt;
      my @current;&lt;br /&gt;
   &lt;br /&gt;
      while ( my $value = $values-&amp;amp;gt;Next ) {&lt;br /&gt;
   &lt;br /&gt;
          push @current, $value-&amp;amp;gt;Name;&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
      foreach my $entry (@lines) {&lt;br /&gt;
          unless ( grep { $entry eq $_ } @current ) {&lt;br /&gt;
              print STDERR &amp;quot;Adding &amp;quot; . $entry . &amp;quot;\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
              my ( $ret, $val ) = $cf-&amp;amp;gt;AddValue( Name =&amp;amp;gt; $entry );&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   print STDERR &amp;quot;Done\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   sub help {&lt;br /&gt;
   &lt;br /&gt;
   print &amp;amp;lt;&amp;amp;lt;EOF&lt;br /&gt;
   &lt;br /&gt;
   $0 is a simple RT tool to add values to a custom field.&lt;br /&gt;
   It takes several arguments:&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
    --field    The id or name of the custom field you&#039;d like to work with&lt;br /&gt;
    --update   Add values to this field, but do not prune unused files&lt;br /&gt;
    --replace  Make the custom field contain only the values listed&lt;br /&gt;
    --verbose  Show progress messages&lt;br /&gt;
   &lt;br /&gt;
   This script expects a list of potential custom field values,&lt;br /&gt;
   one per line to be fed to STDIN.&lt;br /&gt;
   &lt;br /&gt;
   Example:&lt;br /&gt;
   &lt;br /&gt;
   $0 --field &amp;quot;My CF Name&amp;quot; --update &amp;amp;lt; list_of_values&lt;br /&gt;
   &lt;br /&gt;
   EOF&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
   &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The replace switch seems to update on version 3.8.7. (SJN)&lt;/div&gt;</summary>
		<author><name>Othomas</name></author>
	</entry>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=ImportCustomFieldValues&amp;diff=26314</id>
		<title>ImportCustomFieldValues</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=ImportCustomFieldValues&amp;diff=26314"/>
		<updated>2016-08-06T16:15:00Z</updated>

		<summary type="html">&lt;p&gt;Othomas: /* import-custom-field-values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==import-custom-field-values==&lt;br /&gt;
&lt;br /&gt;
I use this script to populate a &amp;quot;select one from many&amp;quot; custom field from a text file generated from a database query.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;  #!/usr/bin/perl&lt;br /&gt;
   &lt;br /&gt;
   use warnings;&lt;br /&gt;
   use strict;&lt;br /&gt;
   &lt;br /&gt;
   use lib qw(/opt/rt3/local/lib /opt/rt3/lib);&lt;br /&gt;
   use Getopt::Long;&lt;br /&gt;
   &lt;br /&gt;
   use RT;&lt;br /&gt;
   RT::LoadConfig();&lt;br /&gt;
   RT::Init();&lt;br /&gt;
   &lt;br /&gt;
   my %args;&lt;br /&gt;
   &lt;br /&gt;
   GetOptions(\%args, &#039;field=s&#039;, &#039;update&#039;,&#039;replace&#039; ,&#039;help&#039;, &#039;verbose&#039;);&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
    if ($args{&#039;help&#039;} || !($args{&#039;update&#039;}||$args{&#039;replace&#039;})  ){&lt;br /&gt;
      help();&lt;br /&gt;
      exit;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
   my @lines = &amp;amp;lt;STDIN&amp;amp;gt;;&lt;br /&gt;
   &lt;br /&gt;
   map {chomp} @lines;&lt;br /&gt;
   &lt;br /&gt;
   my $cf = RT::CustomField-&amp;amp;gt;new(RT-&amp;amp;gt;SystemUser);&lt;br /&gt;
   &lt;br /&gt;
   $cf-&amp;amp;gt;Load( $args{&#039;field&#039;} );&lt;br /&gt;
   unless ( $cf-&amp;amp;gt;id ) {&lt;br /&gt;
      die &amp;quot;Couldn&#039;t find that custom field\n&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   if ( $args{&#039;replace&#039;} ) {&lt;br /&gt;
      my $values = $cf-&amp;amp;gt;Values;&lt;br /&gt;
      my %map;&lt;br /&gt;
   &lt;br /&gt;
      while ( my $value = $values-&amp;amp;gt;Next ) {&lt;br /&gt;
          unless (grep {$value-&amp;amp;gt;Name} @lines) {&lt;br /&gt;
           print STDERR &amp;quot;Deleting &amp;quot; . $value-&amp;amp;gt;Name . &amp;quot;\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
              $value-&amp;amp;gt;Delete();&lt;br /&gt;
          }&lt;br /&gt;
   &lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   if ( $args{&#039;update&#039;} || $args{&#039;replace&#039;} ) {&lt;br /&gt;
      my $values = $cf-&amp;amp;gt;Values;&lt;br /&gt;
      my @current;&lt;br /&gt;
   &lt;br /&gt;
      while ( my $value = $values-&amp;amp;gt;Next ) {&lt;br /&gt;
   &lt;br /&gt;
          push @current, $value-&amp;amp;gt;Name;&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
      foreach my $entry (@lines) {&lt;br /&gt;
          unless ( grep { $entry eq $_ } @current ) {&lt;br /&gt;
              print STDERR &amp;quot;Adding &amp;quot; . $entry . &amp;quot;\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
              my ( $ret, $val ) = $cf-&amp;amp;gt;AddValue( Name =&amp;amp;gt; $entry );&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   print STDERR &amp;quot;Done\n&amp;quot; if ($args{&#039;verbose&#039;});&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   sub help {&lt;br /&gt;
   &lt;br /&gt;
   print &amp;amp;lt;&amp;amp;lt;EOF&lt;br /&gt;
   &lt;br /&gt;
   $0 is a simple RT tool to add values to a custom field.&lt;br /&gt;
   It takes several arguments:&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
    --field    The id or name of the custom field you&#039;d like to work with&lt;br /&gt;
    --update   Add values to this field, but do not prune unused files&lt;br /&gt;
    --replace  Make the custom field contain only the values listed&lt;br /&gt;
    --verbose  Show progress messages&lt;br /&gt;
   &lt;br /&gt;
   This script expects a list of potential custom field values,&lt;br /&gt;
   one per line to be fed to STDIN.&lt;br /&gt;
   &lt;br /&gt;
   Example:&lt;br /&gt;
   &lt;br /&gt;
   $0 --field &amp;quot;My CF Name&amp;quot; --update &amp;amp;lt; list_of_values&lt;br /&gt;
   &lt;br /&gt;
   EOF&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
   &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The replace switch seems to update on version 3.8.7. (SJN)&lt;/div&gt;</summary>
		<author><name>Othomas</name></author>
	</entry>
</feed>