X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FCondition%2FCustomFieldEquals.pm;fp=rt%2Flib%2FRT%2FCondition%2FCustomFieldEquals.pm;h=69dedcbcab0636fc2faa4945b6b1ae749344a095;hb=548b94eafa4bc90680e13f015445b6833b065c73;hp=0000000000000000000000000000000000000000;hpb=f263d9c5f3fa07442faadd9000aaad7275892f8e;p=freeside.git diff --git a/rt/lib/RT/Condition/CustomFieldEquals.pm b/rt/lib/RT/Condition/CustomFieldEquals.pm new file mode 100644 index 000000000..69dedcbca --- /dev/null +++ b/rt/lib/RT/Condition/CustomFieldEquals.pm @@ -0,0 +1,39 @@ +package RT::Condition::CustomFieldEquals; +use base 'RT::Condition'; +use strict; + +=head2 IsApplicable + +If a custom field has a value equal to some specified value. + +=cut + +# Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06 +# Simplified to avoid carrying old schema around. The new mechanics are that +# the ScripCondition's "Argument" is the custom field name = value. If the +# transaction initially sets the CF value to a the specified value, or +# changes it from not equaling to equaling the specified value, the condition +# returns true. +# Don't use this on custom fields that allow multiple values. + +sub IsApplicable { + my $self = shift; + my $trans = $self->TransactionObj; + my $scrip = $self->ScripObj; + my ($field, $value) = split('=', $self->Argument, 2); + + if ($trans->Type eq 'Create') { + return ($trans->TicketObj->FirstCustomFieldValue($field) eq $value); + } + if ($trans->Type eq 'CustomField') { + my $cf = RT::CustomField->new($self->CurrentUser); + $cf->Load($field); + return $trans->Field == $cf->Id + and ($trans->NewValue eq $value) + and ($trans->OldValue ne $value) + } + return undef; +} + +1; +