[rt-users] Calling method Headers in Custom Condition

Ruslan Zakirov ruslan.zakirov at gmail.com
Thu Apr 27 23:00:41 EDT 2006


Create transactions may have no attachments too. You have to check
that the object is defined:

my $attachment = $self->TransactionObj->Attachments->First;
return 0 unless $attachment;

On 4/28/06, john habermann <john.habermann at wilderness.org.au> wrote:
> Hi Todd
>
> On 4/28/06, Todd Chapman <todd at chaka.net> wrote:
> > Your scrip runs on every transaction that happens on the
> > ticket. Not every transaction has attachments. You need
> > to see if it is a Create transaction before checking
> > headers.
> >
> > return 0 if $self->TransactionObj->Type eq 'Create';
>
> Thank you very much for your help. I now have the following code and
> it works great.
>
> return 0 if $self->TransactionObj->Type ne 'Create';
> my $header = $self->TransactionObj->Attachments->First->Headers();
> $header =~ s/\n\s+/ /g;
> my $formname = '';
> if ($header =~ /^RT-Formname: (.*?)$/m) {
>         $formname = $1;
>         $RT::Logger->debug("the headers are $formname");
> }
> else {
>         $RT::Logger->debug("didn't match");
> }
> $RT::Logger->debug("the formname is $formname");
> return undef unless ($formname eq "Database");
> return 1;
>
> cheers
> john
>
> >
> > -Todd
> >
> > On Thu, Apr 27, 2006 at 05:05:03PM +1000, john habermann wrote:
> > > Hi
> > >
> > > I have a queue called database which had been setup to recieve emails
> > > from a form. I had set up a simple approval process by following the
> > > wiki so I created an approv-database queue and then have a template in
> > > the database queue that creates a Ticket in the approv-database queue
> > > when a ticket is created in the database queue.
> > >
> > > The usage of the database queue has expanded beyond just accepting
> > > emails from the form and other tickets that are created in it don't
> > > need to be approved so I have been trying to change the database queue
> > > so that only tickets created by the form emails will trigger an
> > > approval.
> > >
> > > To do this I have the form inserting a header "RT-Formname" and I then
> > > changed the "Request Approval" scip in the database queue so it used a
> > > custom condition rather than the default "On create" condition. This
> > > is what I have in my Custom Condition:
> > > --------------------------------
> > > my $header = $self->TransactionObj->Attachments->First->Headers();
> > > $header =~ s/\n\s+/ /g;
> > > my $formname = '';
> > > if ($header =~ /^Formname: (.*?)$/m) {
> > >         $formname = $1;
> > >         $RT::Logger->debug("the headers are $formname");
> > > }
> > > else {
> > >         $RT::Logger->debug("didn't match");
> > > }
> > > $RT::Logger->debug("the formname is $formname");
> > > return undef unless ($formname eq "Database");
> > > return 1;
> > > -------------------------------
> > >
> > > This appears to work fine as if I create a ticket through the web
> > > interface in RT then the Request Approval scrip is not called and a
> > > ticket is created that doesn't trigger the approval process. When I
> > > send in a email from the form the approval process is triggered as
> > > before so a ticket is created that is pending approval but even though
> > > it appears to work fine and the tickets are created I am getting this
> > > in the rt.log file:
> > >
> > > ------------------------------
> > > [Thu Apr 27 06:24:25 2006] [error]: Scrip 16 IsApplicable failed:
> > > Can't call method "Headers" on an undefined value at (eval 602) line
> > > 1.
> > >
> > > Stack:
> > >   [(eval 602):1]
> > >   [/usr/share/request-tracker3.4/lib/RT/ScripCondition_Overlay.pm:219]
> > >   [/usr/share/request-tracker3.4/lib/RT/Scrip_Overlay.pm:438]
> > >   [/usr/share/request-tracker3.4/lib/RT/Scrips_Overlay.pm:228]
> > >   [/usr/share/request-tracker3.4/lib/RT/Transaction_Overlay.pm:160]
> > >   [/usr/share/request-tracker3.4/lib/RT/Record.pm:1373]
> > >   [/usr/share/request-tracker3.4/lib/RT/Ticket_Overlay.pm:3439]
> > >   [/usr/share/request-tracker3.4/lib/RT/Ticket_Overlay.pm:3176]
> > >   [(eval 579):14]
> > >   [/usr/share/request-tracker3.4/lib/RT/ScripAction_Overlay.pm:220]
> > >   [/usr/share/request-tracker3.4/lib/RT/Scrip_Overlay.pm:477]
> > >   [/usr/share/request-tracker3.4/lib/RT/Scrips_Overlay.pm:235]
> > >   [/usr/share/request-tracker3.4/lib/RT/Transaction_Overlay.pm:160]
> > >   [/usr/share/request-tracker3.4/lib/RT/Record.pm:1373]
> > >   [/usr/share/request-tracker3.4/lib/RT/Ticket_Overlay.pm:3439]
> > >   [/usr/share/request-tracker3.4/lib/RT/Ticket_Overlay.pm:3176]
> > >   [/usr/share/request-tracker3.4/html/Approvals/index.html:80]
> > >   [/usr/share/request-tracker3.4/html/autohandler:215]
> > >  (/usr/share/request-tracker3.4/lib/RT/Condition/UserDefined.pm:67)
> > > [Thu Apr 27 06:24:25 2006] [debug]: About to commit scrips for
> > > transaction #7809
> > > (/usr/share/request-tracker3.4/lib/RT/Transaction_Overlay.pm:167)
> > > -----------------------------------
> > > I also appear to be getting this notice when other tickets are being
> > > created in other queues as I just noticed that it appeared in the log
> > > when some created a ticket in the support queue.
> > >
> > > I am thinking that it is something to do with IsApplicable but not
> > > quite sure that is supposed to apply given that the code is being
> > > executed through the Userdefinied.pm condition. If anyone can shed any
> > >  light or point me to some more info on this subject I would
> > > appreciate it, have looked on the Wiki and also in the RT Essentials
> > > book but couldn't find much that helped me figure out why this error
> > > was happening although it helped me figure out how to to get this far.
> > >
> > > cheers
> > > John
> > > --
> > > John Habermann
> > > The Wilderness Society
> > > www.wilderness.org.au
> > > _______________________________________________
> > > http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> > >
> > > Community help: http://wiki.bestpractical.com
> > > Commercial support: sales at bestpractical.com
> > >
> > >
> > > Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> > > Buy a copy at http://rtbook.bestpractical.com
> > >
> > >
> > > We're hiring! Come hack Perl for Best Practical: http://bestpractical.com/about/jobs.html
> >
>
>
> --
> John Habermann
> The Wilderness Society
> www.wilderness.org.au
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>
>
> We're hiring! Come hack Perl for Best Practical: http://bestpractical.com/about/jobs.html
>


--
Best regards, Ruslan.


More information about the rt-users mailing list