How to get old and new values from specific CF

Hi there,
I can’t figure how to know in a scrip if some CF changes its value. Well, the code is at the first glance quite clear:

return 0 unless ($self->TransactionObj->Type eq "CustomField");
my $old = $self->TransactionObj->OldValue;
my $new = $self->TransactionObj->NewValue;

But I am confused how to select the custom field which this should apply on. When changing only one custom field at a time, it’s OK. When changing more custom fields at once, it’s giving various results because this scrip triggers on various transactions. Maybe the condition is wrong because there should be something like

return 0 unless (($self->TransactionObj->Type eq "CustomField") && ($self->TransactionObj->Name eq "CFname"));

But there is not such a thing.

The RT::CustomField class doesn’t have any OldValue so I can not use something like

my $cf = $self->TransactionObj->LoadCustomFieldByIdentifier('CFname');
my $old = $cf->OldValue; #error RT::CustomField::OldValue Unimplemented

And I can not also use


because this gives me only the actual value but not the old one as “OldValue” is also not defined for class RT::Ticket.
Does anybody have a hint for this? :slight_smile:

It looks like you could do a check for Type ‘CustomField’ on the TransactionObj and check against the ID value of the custom field(s) in question:

return 0 unless $self->TransactionObj->Type eq 'CustomField';

my $customfield = $self->TicketObj->LoadCustomFieldByIdentifier('one');
return 0 unless $self->TransactionObj->Field eq $customfield->Id;

return 1;

Then you can call $self->TransactionObj->OldValue once you have identified which custom field is being updated. Does this help?

Thank you Craig, that’s it.

1 Like