+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',
+ );
+
+ # Promise some kind of ordering
+ $self->OrderBy( FIELD => 'Description' );
+
+ # we call Count below, but later we always do search
+ # so just do search and get count from results
+ $self->_DoSearch if $self->{'must_redo_search'};
+
+ $RT::Logger->debug(
+ "Found ". $self->Count ." scrips for $args{'Stage'} stage"
+ ." with applicable type(s) $args{'Type'}"
+ ." for txn #".$self->{TransactionObj}->Id
+ ." on ticket #".$self->{TicketObj}->Id
+ );
+}