summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Condition/CustomFieldChange.pm
blob: b9228a50f92200b2b85b1a2417d071027f5c0f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package RT::Condition::CustomFieldChange;
use base 'RT::Condition';
use strict;

=head2 IsApplicable

If a custom field has a particular value.

=cut

# Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06

sub IsApplicable {
    my $self = shift;
    my $trans = $self->TransactionObj;
    my $scrip = $self->ScripObj;
    my %Rules = $self->Rules;
    my ($field, $value) = @Rules{'field', 'value'};
    return if !defined($field) or !defined($value);

    if ($trans->Type eq 'Create') {
        return 1 if $trans->TicketObj->FirstCustomFieldValue($field) eq $value;
    }
    if ($trans->Type eq 'CustomField') {
        my $cf = RT::CustomField->new($self->CurrentUser);
        $cf->Load($field);
        return 1 if $trans->Field == $cf->Id and $trans->NewValue eq $value;
    }
    return undef;
}

sub Options {
  my $self = shift;
  my %args = ( 'QueueObj' => undef, @_ );
  my $QueueObj = $args{'QueueObj'};
  my $cfs = $QueueObj->TicketCustomFields();
  my @fieldnames;
  while ( my $cf = $cfs->Next ) {
    push @fieldnames, $cf->Name, $cf->Name;
  }
  return (
    { 
      'name'    => 'field',
      'label'   => 'Custom Field',
      'type'    => 'select',
      'options' => \@fieldnames,
    },
    {
      'name'    => 'value',
      'label'   => 'Value',
      'type'    => 'text',
    },
  );
}
1;