[rt-users] Changing Scrip Order Precedence?

Joby Walker joby at u.washington.edu
Fri Jan 20 20:07:38 EST 2006


Not by default.

You can activate and use the Batch stage but that has limited usefulness.

You can extend RT to order scrips for you though.

In our Scrips_Local.pm we have the following method:

---------------------------------------------------------------------
sub _FindScrips {
    my $self = shift;
    my %args = (
                 Stage => undef,
                 Type => undef,
                 @_ );


    $self->LimitToQueue( $self->{'TicketObj'}->QueueObj->Id )
      ;    #Limit it to  $Ticket->QueueObj->Id
    $self->LimitToGlobal();
      # or to "global"

    $self->Limit( FIELD => "Stage", VALUE => $args{'Stage'} );

    my $ConditionsAlias = $self->NewAlias('ScripConditions');

    $self->Join(
        ALIAS1 => 'main',
        FIELD1 => 'ScripCondition',
        ALIAS2 => $ConditionsAlias,
        FIELD2 => 'id'
    );
    #We only want things where the scrip applies to this sort of transaction
    # TransactionBatch stage can define list of transaction
    foreach( split /\s*,\s*/, ($args{'Type'} || '') ) {
        $self->Limit(
            ALIAS           => $ConditionsAlias,
            FIELD           => 'ApplicableTransTypes',
            OPERATOR        => 'LIKE',
            VALUE           => $_,
            ENTRYAGGREGATOR => 'OR',
        )
    }

    # Or where the scrip applies to any transaction
    $self->Limit(
        ALIAS           => $ConditionsAlias,
        FIELD           => 'ApplicableTransTypes',
        OPERATOR        => 'LIKE',
        VALUE           => "Any",
        ENTRYAGGREGATOR => 'OR',
    );

    $self->OrderBy( FIELD => 'description');

    $RT::Logger->debug("Found ".$self->Count. " scrips");
}
---------------------------------------------------------------------

The only thing that we changed was is the "$self->OrderBy( FIELD =>
'description');" line near the end of the method.  This sorts scrips by
the description of the scrip.  Thus a scrips description just needs to
start with a prefix to determine ordering (we use a three diget number
-- so we won't ever have to reorder).

Joby Walker
ITI SSG, C&C, University of Washington


Mike Patterson wrote:
> RT folks,
> 
> Is there any way I can change the order in which scrips are evaluated?
> 
> In my case I'm working on a scrip that adds a manager as an AdminCc if
> an annoying person is submitting a ticket (or is Cc'd on one).
> It works fine but, the only problem is that the other "On Create" scrips
> seem to send out their emails before the person gets added as a
> AdminCc.  So that AdminCc that I just added misses that message, but
> they get other future correspondence on that ticket.
> 
> Any insights into on how this works or how to  fix it are appreciated.
> 
> My Scrip:
> -------------------------------------------------------
> Description: Add AdminCc if lunkhead
> Condition: OnCreate
> Action: User Defined
> Template: Global template: Blank
> Stage: TransactionCreate
> Custom condition:
> Custom action preparation code:
> 
> #goal of prepcode: if certain folks are Requestors,Cc,AdminCc (e.g
> dog at mydomain.com)
> #and other people are not already Requestors,Cc,AdminCc (cat at mydomain.com)
> #then go to action cleanup code section below, else exit (e.g. return 0)
> 
> my $people = $self->TicketObj->RequestorAddresses;
> $people .= $self->TicketObj->AdminCcAddresses;
> $people .= $self->TicketObj->CcAddresses;
> 
>  if (($people =~ /dog\@/i) && ($people !~ /cat\@/i)) {
>    return 1;
>    }
> return 0;
> 
> Custom action cleanup code:
> #add cat at mydomain.com as an AdminCc if prep code above returns true
> my $admincclist = $self->TicketObj->AdminCc;
> 
> my $user = RT::User->new($RT::SystemUser);
> $user->LoadByEmail('cat at mydomain.com');
> 
> $admincclist->AddMember($user->Id);
> return 1;
> ---------------------------------------------
> BTW I'm leaning on examples from here:
> http://wiki.bestpractical.com/index.cgi?AddAdminCc
> 
> My RT test box:
> RT 3.4.4, FedoraCore4, Perl 5.8.6, HTML Mason 1.3101, mod_perl2, Apache2
> 



More information about the rt-users mailing list