[rt-users] Apply a custom field to a queue

Firas Batal firas.batal at ericsson.com
Thu Apr 3 17:14:53 EDT 2008

Hi everyone,

I am using RT 3.6.3 on a Fedora core 8 Box.  

This is my dilemma: I am writing a Perl script that enables me to create
custom fields from an external Excel spreadsheet.   I would like to
create one custom field and apply it to a number of queues, just as we
can do that manually using the web interface.  

In the beginning, I have used the following API:

    my $system_user = initialise_rt();
    my $rtObj_cf = RT::CustomField->new($system_user);
    my $rt_queue = RT::Queue->new($system_user);

foreach my $queue ( keys %{ $rec->{queue_record} } ) {
        print "queue: $queue \n";
        my $queue_id = $rt_queue->Load($queue);
        print qq~queue id: $queue_id\n~;
        next if ( !defined $queue_id || !$queue_id || $queue eq '' );
        foreach my $cf ( keys %{ $rec->{lcf_record} } ) {
            if ( defined $rec->{lcf_record}{$cf}{Pattern} &&
$rec->{lcf_record}{$cf}{Pattern} ne '' &&
$rec->{lcf_record}{$cf}{Pattern} =~ /Yes|Mandatory/i ) {
                foreach my $site ( keys %{ $rec->{site_record} } ) {
                    my ( $id, $msg ) = $rtObj_cf->Create(
                        Name        => $site. '_' . $queue . '_' . $cf,
                        Queue       => $queue_id,
                        Description => 'Custom Field ' . $site. '_' .
$queue . '_' .  $cf,
                        Pattern     => '(?#Mandatory).',
                        SortOrder   => '1',
                        Type        => $rec->{lcf_record}{$cf}{Type}
                    if ( !$id ) {
                        print qq~Problem to create the costum field:
$cf, message: $msg \n~;

The following segment of code loops through all queues defined in the
excel spread-sheet and create custom fields for each queue according to
the number of custom fields I have.  So, if I have 3 custom fields in
the excel sheet and 4 queues, then the total number of custom fields is

The problem with this approach is that you create redundant custom
fields (or access custom fields).  What I would like to do is to take
advantage, using a script; of the facility of which RT 3.6.0+ can create
custom fields and apply them to each queue.  So, instead of creating 12
custom fields, I need to create 3 custom fields and apply to all queues.

Is there an API that one could use, after creating the custom field, to
apply the custom field to the queue under question?

Thanks and I apologize for the innconvenience

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20080403/f8c5b932/attachment.htm>

More information about the rt-users mailing list