[rt-users] how to access content for an attachment in scrip?

John Alberts John.Alberts at exlibrisgroup.com
Thu Jul 7 21:15:30 EDT 2011


Thank you.  I'll give this a try tomorrow.  I figured there had to be a
simpler way to get what I wanted, but I am just fumbling around trying to
figure things out.  It actually took me almost 5 hours of trial and error
to get what I have working.

John







On 7/7/11 7:25 PM, "Thomas Sibley" <trs at bestpractical.com> wrote:

>On 07/07/2011 07:21 PM, John Alberts wrote:
>> Thanks for the tip.  It led me in the right direction and I ended up
>>with
>> this, which finally works.
>> 
>> my $T_Obj = $self->TicketObj;
>>    my $a = RT::Attachments->new($self->TransactionObj->CurrentUser);
>>    my $b = RT::Attachments->new($self->TransactionObj->CurrentUser);
>>    my $AttachObj = $self->TransactionObj->Attachments;
>>    while ( $a = $AttachObj->Next ) {
>>   $b = $a;
>>   next unless $a->Filename eq "env-vars.txt";
>>            }
>>    my $content = $b->Content;
>
>The above will fail when env-vars.txt isn't the last attachment RT
>parsed.  Try this (untested) much simpler version:
>
>    my $attachments = $self->TransactionObj->Attachments;
>    my $content;
>    while (my $attach = $attachments->Next) {
>        if ($attach->Filename eq "env-vars.txt") {
>            $content = $attach->Content;
>            last; # we found it, no need to keep looking
>        }
>    }
>    # use $content for whatever you'd like here
>
>There are better, faster ways to do this than looping over the
>attachments, but looping is the easiest to understand.
>
>Thomas
>
>--------
>2011 Training: http://bestpractical.com/services/training.html




More information about the rt-users mailing list