+sub Ticket {
+ my $self = shift;
+ return $self->ObjectId;
+}
+
+sub TicketObj {
+ my $self = shift;
+ return $self->Object;
+}
+
+sub OldValue {
+ my $self = shift;
+ if (my $type = $self->__Value('ReferenceType')) {
+ my $Object = $type->new($self->CurrentUser);
+ $Object->Load($self->__Value('OldReference'));
+ return $Object->Content;
+ }
+ else {
+ return $self->__Value('OldValue');
+ }
+}
+
+sub NewValue {
+ my $self = shift;
+ if (my $type = $self->__Value('ReferenceType')) {
+ my $Object = $type->new($self->CurrentUser);
+ $Object->Load($self->__Value('NewReference'));
+ return $Object->Content;
+ }
+ else {
+ return $self->__Value('NewValue');
+ }
+}
+
+sub Object {
+ my $self = shift;
+ my $Object = $self->__Value('ObjectType')->new($self->CurrentUser);
+ $Object->Load($self->__Value('ObjectId'));
+ return($Object);
+}
+
+sub FriendlyObjectType {
+ my $self = shift;
+ my $type = $self->ObjectType or return undef;
+ $type =~ s/^RT:://;
+ return $self->loc($type);
+}
+
+=head2 UpdateCustomFields
+
+ Takes a hash of
+
+ CustomField-<<Id>> => Value
+ or
+
+ Object-RT::Transaction-CustomField-<<Id>> => Value parameters to update
+ this transaction's custom fields
+
+=cut
+
+sub UpdateCustomFields {
+ my $self = shift;
+ my %args = (@_);
+
+ # This method used to have an API that took a hash of a single
+ # value "ARGSRef", which was a reference to a hash of arguments.
+ # This was insane. The next few lines of code preserve that API
+ # while giving us something saner.
+
+
+ # TODO: 3.6: DEPRECATE OLD API
+
+ my $args;
+
+ if ($args{'ARGSRef'}) {
+ $args = $args{ARGSRef};
+ } else {
+ $args = \%args;
+ }
+
+ foreach my $arg ( keys %$args ) {
+ next
+ unless ( $arg =~
+ /^(?:Object-RT::Transaction--)?CustomField-(\d+)/ );
+ next if $arg =~ /-Magic$/;
+ my $cfid = $1;
+ my $values = $args->{$arg};
+ foreach
+ my $value ( UNIVERSAL::isa( $values, 'ARRAY' ) ? @$values : $values )
+ {
+ next unless length($value);
+ $self->_AddCustomFieldValue(
+ Field => $cfid,
+ Value => $value,
+ RecordTransaction => 0,
+ );
+ }
+ }
+}
+
+
+
+=head2 CustomFieldValues
+
+ Do name => id mapping (if needed) before falling back to RT::Record's CustomFieldValues
+
+ See L<RT::Record>
+
+=cut
+
+sub CustomFieldValues {
+ my $self = shift;
+ my $field = shift;
+
+ if ( UNIVERSAL::can( $self->Object, 'QueueObj' ) ) {
+
+ unless ( $field =~ /^\d+$/o ) {
+ my $CFs = RT::CustomFields->new( $self->CurrentUser );
+ $CFs->Limit( FIELD => 'Name', VALUE => $field);
+ $CFs->LimitToLookupType($self->CustomFieldLookupType);
+ $CFs->LimitToGlobalOrObjectId($self->Object->QueueObj->id);
+ $field = $CFs->First->id if $CFs->First;
+ }
+ }
+ return $self->SUPER::CustomFieldValues($field);
+}
+
+# }}}
+
+# {{{ sub CustomFieldLookupType
+
+=head2 CustomFieldLookupType
+
+Returns the RT::Transaction lookup type, which can
+be passed to RT::CustomField->Create() via the 'LookupType' hash key.
+
+=cut
+
+# }}}
+
+sub CustomFieldLookupType {
+ "RT::Queue-RT::Ticket-RT::Transaction";
+}
+