Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Robrt (1414)

  (email not shown publicly)

robert at perl dot org

Journal of Robrt (1414)

Sunday July 17, 2005
02:25 AM

RT: Mass Custom Field Update

[ #25746 ]

Steve Peters asked if I could consolidate the Win32 and mswwin32 types in the Operating System CustomField in perlbug. Definitely a reasonable request, especially since we couldn't figure out what the difference was.

First try was to use RT's bulk update, but it didn't want to let me change custom fields... so... I wrote a script:

use strict;
use warnings;
use RT;
use RT::Queues;
use RT::Tickets;
my $tx = RT::Tickets->new($RT::SystemUser);
my $cf = RT::CustomField->new($RT::SystemUser);
my $q  = RT::Queue->new($RT::SystemUser);
$tx->FromSQL(q[queue="perl5" and "cf.perl5.{Operating System}" = "Win32"]);
$cf->LoadByNameAndQueue(Queue => $q->Id,
                        Name => 'Operating System');
while (my $t = $tx->Next) {
    my $os = $t->FirstCustomFieldValue("Operating System");
    $t->DeleteCustomFieldValue(Field => $cf->Id,
                               Value => $os);
    $t->AddCustomFieldValue(Field => $cf->Id,
                            Value => 'mswin32');

It gets the job done. There's a few things that aren't quite "simple enough"... but we'll see about knocking those out in the next version.

Learn more about RT in the soon to be published book RT Essentials.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.