I have 4 custom fields in this scenario:

1st Approval
2nd Approval

Those are both "Select One Value" dropdowns that apply to tickets. Permissions 
are "view" for Privileged and modify for a group allowed to approve these 
tickets.

I have 2 additional fields:
1st Approved By
2nd Approved By

Both are "Enter one value" that apply to tickets. Privileged has view and there 
are no other permissions set (I don't want users able to set this field, 
essentially "read only" - you'll see why in a minute).

If an approver makes a selection in one of the select boxes, I have scrip that 
will enter a value in the corresponding "approved by" field.

Here's the weird thing - it works perfect for the "1st" boxes. But when I 
choose a value for the 2nd approval, it sets it, then reverts it back to the 
previous value (I've tried modifying the field as a superuser to confirm its 
rolling back and not just deleting the value). The scrip code from the "1st" 
check/set was copy/pasted and only the variables changed to reflect the 
different column ids.

Here is the snippet from the ticket history:
Fri Dec 02 09:35:37 2011 Brent Wiese - (CC) 2nd Approval No changed to Yes
Fri Dec 02 09:35:37 2011 The RT System itself - (CC) Seconded By Approved by: 
Brent Wiese added
Fri Dec 02 09:35:37 2011 Brent Wiese - (CC) Seconded By Approved by: Brent 
Wiese deleted

Scrip:
Condition: User Defined
Action: User Defined
Template: Global template: Blank
Stage: TransactionCreate

Custom condition:
unless ($self->TransactionObj->Type eq "CustomField" ) {
return 0;
}
1;

Prep:
# Set Field to ID of (CC) 1st Approval:
my $CFid = 5;
# Set to ID of (CC) 1st Approved By:
my $CFAppID = 18;
# Set Field to ID of (CC) 2nd Approval:
my $CFid2 = 17;
# Set to ID of (CC) 2nd Approved By:
my $CFAppID2 = 20;
# Set to 1 if you want an extra line that the scrip made changes logged in the 
ticket history
my $rec = 1;

my $cf_obj = RT::CustomField->new($RT::SystemUser);

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $person = $trans->CreatorObj->RealName;

if ( $self->TransactionObj->Type eq "CustomField" && 
$self->TransactionObj->Field == $CFid ) {

                                $cf_obj->LoadByName( Name => $CFAppID );

                                my $val = $ticket->FirstCustomFieldValue($CFid);
                                if ($val eq 'Yes') {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Approved by: $person", 
RecordTransaction => $rec );
                                                } elsif ($val eq 'No') {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Disapproved by: 
$person", RecordTransaction => $rec );
                                                } else {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Pending", 
RecordTransaction => $rec );
                                                }
}

if ( $self->TransactionObj->Type eq "CustomField" && 
$self->TransactionObj->Field == $CFid2 ) {

                                $cf_obj->LoadByName( Name => $CFAppID2 );

                                my $val2 = 
$ticket->FirstCustomFieldValue($CFid2);
                                if ($val2 eq 'Yes') {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Approved by: $person", 
RecordTransaction => $rec );
                                                } elsif ($val2 eq 'No') {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Disapproved by: 
$person", RecordTransaction => $rec );
                                                } else {
                                                
$ticket->AddCustomFieldValue(Field => $cf_obj, Value => "Pending", 
RecordTransaction => $rec );
                                                }
}
return 1;  <-- I've tried return 0 here too and no difference

No cleanup.

It was working this way before I added the $cf_obj variable.  I thought maybe 
hard-coding it to enter the value as RT_System would help, but it made no 
difference.

I tried doing all the code in the custom condition (which is why I'm still 
checking if it's a customfield transaction in the if statement). Works the same 
either way I try it.

Any thoughts?

Thanks,
Brent


--------
RT Training Sessions (http://bestpractical.com/services/training.html)
* Boston — March 5 & 6, 2012

Reply via email to