AutoUpdate Parents with TImeWorked: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[File:Placeholder|right|300px]]
[[File:Placeholder|right|300px]]


<pre>
#############################################################################<br />#
#############################################################################<br />#
# Scrip name: WorkFlow MemberOf on Time<br /># Description: Automatically add "Time Worked" to all vertical and horizontal<br />#             parent tickets<br />#
# Scrip name: WorkFlow MemberOf on Time<br /># Description: Automatically add "Time Worked" to all vertical and horizontal<br /># parent tickets<br />#
# Condition:   User Defined<br /># Action:     User Defined<br /># Template:   Global template: Blank<br /># Stage:       TransactionBatch<br /># Written:     12/10/2010 - Kenn Crocker<br />#
# Condition: User Defined<br /># Action: User Defined<br /># Template: Global template: Blank<br /># Stage: TransactionBatch<br /># Written: 12/10/2010 - Kenn Crocker<br />#
# Modified:   MM/DD/YYYY - Name/comments<br />#
# Modified: MM/DD/YYYY - Name/comments<br />#
#############################################################################<br />#
#############################################################################<br />#
#----------------------------------------------------------------------------<br /># Custom condition:<br />#----------------------------------------------------------------------------<br /># Set initial values
#----------------------------------------------------------------------------<br /># Custom condition:<br />#----------------------------------------------------------------------------<br /># Set initial values
Line 16: Line 17:
return 1;
return 1;


#----------------------------------------------------------------------------<br /># Custom action preparation code:<br />#----------------------------------------------------------------------------<br /># Set initial values
#----------------------------------------------------------------------------
# Custom action preparation code:
#----------------------------------------------------------------------------
# Set initial values


my $trans = $self->TransactionObj;<br />my $ticket = $self->TicketObj;<br />my $Time = (($trans->NewValue) - ($trans->OldValue));<br />my $MemberOf = $ticket->MemberOf;
my $trans = $self->TransactionObj;<br />my $ticket = $self->TicketObj;
my $Time = (($trans->NewValue) - ($trans->OldValue));
my $MemberOf = $ticket->MemberOf;


# get out if current ticket is not a "MemeberOf" (child of some parent)
# get out if current ticket is not a "MemeberOf" (child of some parent)
Line 24: Line 30:
return 0 unless $MemberOf;
return 0 unless $MemberOf;


# Loop thru each parent and add the Child's "TimeWorked" to them<br /># You can skip a parent ticket if it is not in active state by uncommenting<br /># the next statement
# Loop thru each parent and add the Child's "TimeWorked" to them
# You can skip a parent ticket if it is not in active state by uncommenting
# the next statement


while( my $l = $MemberOf->Next )<br />{<br />#     next unless( $l->TargetObj->Status =~ /^(?:new|open|stalled)$/ );<br />my $ParentTime = $l->TargetObj->TimeWorked;<br />my $NewTime = ($ParentTime + $Time);<br />$l->TargetObj->SetTimeWorked($NewTime);<br />}
while( my $l = $MemberOf->Next ) {
    # next unless( $l->TargetObj->Status =~ /^(?:new|open|stalled)$/ );
    my $ParentTime = $l->TargetObj->TimeWorked;
    my $NewTime = ($ParentTime + $Time);
    $l->TargetObj->SetTimeWorked($NewTime);
}


return 1;
return 1;


#----------------------------------------------------------------------------<br /># Custom action cleanup code: None<br />#----------------------------------------------------------------------------<br />return 1;
#----------------------------------------------------------------------------
# Custom action cleanup code: None
#----------------------------------------------------------------------------
return 1;
</pre>

Revision as of 04:51, 1 April 2013

File:Placeholder
#############################################################################<br />#
# Scrip name: WorkFlow MemberOf on Time<br /># Description: Automatically add "Time Worked" to all vertical and horizontal<br /># parent tickets<br />#
# Condition: User Defined<br /># Action: User Defined<br /># Template: Global template: Blank<br /># Stage: TransactionBatch<br /># Written: 12/10/2010 - Kenn Crocker<br />#
# Modified: MM/DD/YYYY - Name/comments<br />#
#############################################################################<br />#
#----------------------------------------------------------------------------<br /># Custom condition:<br />#----------------------------------------------------------------------------<br /># Set initial values

my $trans = $self->TransactionObj;<br />my $ticket = $self->TicketObj;

# Get out if not for "TimeWorked"

return 0 unless ($trans->Type eq 'Set' &&<br />$trans->Field eq 'TimeWorked');

return 1;

#----------------------------------------------------------------------------
# Custom action preparation code:
#----------------------------------------------------------------------------
# Set initial values

my $trans = $self->TransactionObj;<br />my $ticket = $self->TicketObj;
my $Time = (($trans->NewValue) - ($trans->OldValue));
my $MemberOf = $ticket->MemberOf;

# get out if current ticket is not a "MemeberOf" (child of some parent)

return 0 unless $MemberOf;

# Loop thru each parent and add the Child's "TimeWorked" to them
# You can skip a parent ticket if it is not in active state by uncommenting
# the next statement

while( my $l = $MemberOf->Next ) {
    # next unless( $l->TargetObj->Status =~ /^(?:new|open|stalled)$/ );
    my $ParentTime = $l->TargetObj->TimeWorked;
    my $NewTime = ($ParentTime + $Time);
    $l->TargetObj->SetTimeWorked($NewTime);
}

return 1;

#----------------------------------------------------------------------------
# Custom action cleanup code: None
#----------------------------------------------------------------------------
return 1;