diff options
author | mark <mark> | 2011-05-13 23:20:53 +0000 |
---|---|---|
committer | mark <mark> | 2011-05-13 23:20:53 +0000 |
commit | cd34706f94273cf381952f57c5fcb7d6910fbae0 (patch) | |
tree | 8dc42aed01a79850884b1f9e70039336e6e806cd /rt/lib | |
parent | 20950bb21ee5dd8839a05dfcd58efa0a98e48e5a (diff) |
notify on custom field change, #11274
Diffstat (limited to 'rt/lib')
-rw-r--r-- | rt/lib/RT/Condition/CustomFieldTransaction.pm | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/rt/lib/RT/Condition/CustomFieldTransaction.pm b/rt/lib/RT/Condition/CustomFieldTransaction.pm new file mode 100644 index 000000000..137f74aa6 --- /dev/null +++ b/rt/lib/RT/Condition/CustomFieldTransaction.pm @@ -0,0 +1,86 @@ +package RT::Condition::CustomFieldTransaction; +use base 'RT::Condition'; +use strict; + +=head1 NAME + +RT::Condition::CustomFieldTransaction + +=head1 DESCRIPTION + +Returns true if a transaction changed the value of a custom field. Unlike +CustomFieldChange, this condition doesn't care what the value was, only that +it changed. + +=head2 Parameters + +=over 4 + +=item field (string) + +Only return true if the transaction changed a custom field with this name. +If empty, returns true for any CustomField-type transaction. + +=item include_create (boolean) - Also return true for Create-type transactions. +If 'field' is specified, return true if that field is non-empty in the newly +created object. + +=back + +=head2 IsApplicable + +If the transaction has changed the value of a custom field. + +=head1 BUGS + +Probably interacts badly with multiple custom fields with the same name. + +=cut + +sub IsApplicable { + my $self = shift; + my $trans = $self->TransactionObj; + my $scrip = $self->ScripObj; + my %Rules = $self->Rules; + my ($field, $include_create) = @Rules{'field', 'include_create'}; + + if ( $include_create and $trans->Type eq 'Create' ) { + return 1 if !defined($field); + return 1 if defined($trans->TicketObj->FirstCustomFieldValue($field)); + } + if ($trans->Type eq 'CustomField') { + return 1 if !defined($field); + my $cf = RT::CustomField->new($self->CurrentUser); + $cf->Load($field); + return 1 if defined($cf->Id) and $trans->Field == $cf->Id; + } + return undef; +} + +sub Options { + my $self = shift; + my %args = ( 'QueueObj' => undef, @_ ); + my $cfs = RT::CustomFields->new($self->CurrentUser); + # Allow any ticket custom field to be selected; if it doesn't apply to the + # ticket, it will never contain a value and that's fine. + $cfs->LimitToLookupType('RT::Queue-RT::Ticket'); + my @fieldnames = ('', '(any field)'); + while ( my $cf = $cfs->Next ) { + push @fieldnames, $cf->Name, $cf->Name; + } + return ( + { + 'name' => 'field', + 'label' => 'Custom Field', + 'type' => 'select', + 'options' => \@fieldnames, + }, + { + 'name' => 'include_create', + 'label' => 'Trigger on ticket creation', + 'type' => 'checkbox', + }, + ); +} +1; + |