diff options
author | mark <mark> | 2011-02-17 03:47:50 +0000 |
---|---|---|
committer | mark <mark> | 2011-02-17 03:47:50 +0000 |
commit | 90edd8a914fd484e649fb0aa051dce7927bd6881 (patch) | |
tree | 24e53dc621cd3825d00a78ad51908cab0906cf3c /rt/lib/RT/Action | |
parent | 01352af8e44b7eb70b2b587ca43ab7ca946f038d (diff) |
TimeWorked-like custom fields, RT#11168
Diffstat (limited to 'rt/lib/RT/Action')
-rw-r--r-- | rt/lib/RT/Action/Accumulate.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rt/lib/RT/Action/Accumulate.pm b/rt/lib/RT/Action/Accumulate.pm new file mode 100644 index 000000000..c4ca667ea --- /dev/null +++ b/rt/lib/RT/Action/Accumulate.pm @@ -0,0 +1,44 @@ +package RT::Action::Accumulate; +use base 'RT::Action'; + +use strict; + +=head1 NAME + +RT::Action::Accumulate - Accumulate a running total in a ticket custom field. + +This action requires a transaction and ticket custom field with the same name. +When a transaction is submitted with a numeric value in that field, the field +value for the ticket will be incremented by that amount. Use this to create +custom fields that behave like the "TimeWorked" field. + +Best used with an "On Update" condition that triggers on any transaction. The +ticket custom field update itself does not a create a transaction. + +The argument to this action is the name of the custom field. They must have +the same name, and should be single-valued fields. + +=cut + +sub Prepare { + my $self = shift; + my $cfname = $self->Argument or return 0; + $self->{'inc_by'} = $self->TransactionObj->FirstCustomFieldValue($cfname); + return ( $self->{'inc_by'} =~ /^(\d+)$/ ); +} + +sub Commit { + my $self = shift; + my $cfname = $self->Argument; + my $newval = $self->{'inc_by'} + + ($self->TicketObj->FirstCustomFieldValue($cfname) || 0); + my ($val) = $self->TicketObj->AddCustomFieldValue( + Field => 'Support time', + Value => $newval, + RecordTransaction => 0, + ); + return $val; +} + +1; + |