Linking a Transaction CF value to a Ticket CF value

I currently have 2 customfields assosated with my tickets. Both will be used
to highlight a ticket to our support team when set to ‘Alert’.

Currently the CF on the ticket is used to updates the required tables and
notify support etc but having a CF on the Transaction would make it easyer
for the user to Alert support and give a description of the issue as many
times the user has forgoten to do this

Ticket CF - ‘Alert_Support’
Trans CF - ‘Alert_Support_T’

what i want to do is to create a script that will detect when the
“Alert_Support_T” CF is updated to ‘Alert’ and then update the
“Alert_Support” CF to ‘Alert’ to allow all the aproprate tables to update to
highlight the ticket to the support team

I have been trying for serveral days to get this working but as im new to RT
i feel like im missing something straight foward

I currently have the following script

Descrition - ZZZ - Test Alert_Support_T trigger
Condition - User Defined
Action - User Defined
Template - Global Template - Blank
Stage - TransactionCreate

###Custom Conditions###

#Set my Variables
my $trans = $self->TransactionObj;
my $type = $trans->Type;

#Check CustomField on Create ticket
if ( $type eq ‘Create’ ) {
return 0 unless $trans->FirstCustomFieldValue(‘Alert_Support_T’) eq
‘Alert’;
}

#check Customfield on ticket update
elsif ( $type eq ‘CustomField’ ) {
# CF can be changed later
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $trans->Field );
return 0 unless $cf->Name eq ‘Alert_Support_T’;
return 0 unless $trans->NewValue eq ‘Alert’;
} else {
return 0;
}
return 1;

###Custom Action###

#Set my Variables
my $ticket = $self->TicketObj;

#CODE - update CF
$ticket->AddCustomFieldValue( Field => ‘Alert_Support’, Value => ‘Alert’ );

return 1;

###Custom Action###

return 1;

i am under the impresion that the script is failing to trigger so i figure
there is an issue with the custom conditions but i cant figure out where

if you could give me any help on this issue it would be a great help

thank you

View this message in context: http://requesttracker.8502.n7.nabble.com/Linking-a-Transaction-CF-value-to-a-Ticket-CF-value-tp54546.html

I currently have 2 customfields assosated with my tickets. Both will be used
to highlight a ticket to our support team when set to ‘Alert’.

Currently the CF on the ticket is used to updates the required tables and
notify support etc but having a CF on the Transaction would make it easyer
for the user to Alert support and give a description of the issue as many
times the user has forgoten to do this

I’m glad I noticed you had started a new thread, so I didn’t reply to
your Load questions on the previous thread.

Ticket CF - ‘Alert_Support’
Trans CF - ‘Alert_Support_T’

Is the Create part working?

#Check CustomField on Create ticket
if ( $type eq ‘Create’ ) {
return 0 unless $trans->FirstCustomFieldValue(‘Alert_Support_T’) eq
‘Alert’;
}

For this part, add debugging:

#check Customfield on ticket update
elsif ( $type eq ‘CustomField’ ) {
# CF can be changed later
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $trans->Field );

You should always check Load
my ($id, $msg) = $cf->Load(“Foo”);
unless ($id) {
RT->Logger->error(“Unable to load Foo: $msg”;
return 0;
}

Use similar RT->Logger calls below to find out where your condition is
exiting.

-kevin

The “if ( $type eq ‘Create’ ) {” & “elsif ( $type eq ‘CustomField’ ) {”
section dont work correctly as there not returning the corect values out
regardless if Alert_Support_T is set to ‘Alert’ or ‘null’

The ‘Create’ section always returns 1 and continualy sends emails and the
‘custonfield’ section always returns 0

Could you explain to me how to add the logger (below) as i get a sintax
error when i try to add it refering to ‘Alert_Support_T’

You should always check Load
my ($id, $msg) = $cf->Load(“Alert_Support_T”");
unless ($id) {
RT->Logger->error(“Unable to load Foo: $msg”;
return 0;
}

View this message in context: http://requesttracker.8502.n7.nabble.com/Linking-a-Transaction-CF-value-to-a-Ticket-CF-value-tp54546p54559.html

The “if ( $type eq ‘Create’ ) {” & “elsif ( $type eq ‘CustomField’ ) {”
section dont work correctly as there not returning the corect values out
regardless if Alert_Support_T is set to ‘Alert’ or ‘null’

The ‘Create’ section always returns 1 and continualy sends emails and the
‘custonfield’ section always returns 0

If it continually sends emails, even on non-creates, that’s
concerning.

Could you explain to me how to add the logger (below) as i get a sintax
error when i try to add it refering to ‘Alert_Support_T’

I missed a closing ) on my example code.

If you get syntax errors, it’s helpful to post the error.

-kevin

You should always check Load
my ($id, $msg) = $cf->Load(“Alert_Support_T”");
unless ($id) {
RT->Logger->error(“Unable to load Foo: $msg”;
)
return 0;
}

-kevin

Ah ok i see where the syntax error is coming from and your right its because
of a missing bracket.

I have now ran the trigger by replying to a ticket and setting the
'Alert_Support_T CF to ‘Alert’ and it produced the following error

Error Log
Stack:
[/opt/rt4/sbin/…/lib/RT/Interface/Email.pm:487]
[/opt/rt4/sbin/…/lib/RT/Action/SendEmail.pm:292]
[/opt/rt4/sbin/…/lib/RT/Action/SendEmail.pm:114]
[/opt/rt4/sbin/…/lib/RT/ScripAction.pm:232]
[/opt/rt4/sbin/…/lib/RT/Scrip.pm:475]
[/opt/rt4/sbin/…/lib/RT/Scrips.pm:188]
[/opt/rt4/sbin/…/lib/RT/Transaction.pm:201]
[/opt/rt4/sbin/…/lib/RT/Record.pm:1504]
[/opt/rt4/sbin/…/lib/RT/Ticket.pm:2297]
[/opt/rt4/sbin/…/lib/RT/Ticket.pm:2193]
[/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:2019]
[/opt/rt4/share/html/Ticket/Display.html:164]
[/opt/rt4/share/html/Ticket/Update.html:300]
[/opt/rt4/share/html/Ticket/autohandler:66]
[/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:634]
[/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:335]
[/opt/rt4/share/html/autohandler:53]
(/opt/rt4/sbin/…/lib/RT/Interface/Email.pm:491)
[Mon Jul 8 09:01:35 2013] [warning]: Couldn’t load object RT::Transaction
#0 (/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:2684

Script Cndition

#Set my Variables
my $txn = $self->TransactionObj;
my $type = $txn->Type;
my $cf = RT::CustomField->new( $self->CurrentUser );

#Test load CF Alert_Support_T
my ($id, $msg) = $cf->Load(“Alert_Support_T”);
unless ($id) {
RT->Logger->error(“Unable to load Alert_Support_T: $msg”);
return 0;
}

if ( $type eq ‘Create’ ) {
# CF can be set on create
return 0 unless
$txn->Creatorobj->FirstCustomFieldValue(‘Alert_Support_T’) eq ‘LFM Support
Required’;

}
elsif ( $type eq ‘CustomField’ ) {
# CF can be changed later
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $txn->Field );

 return 0 unless $cf->Name eq 'Alert_Support_T';
 return 0 unless $txn->NewValue eq 'LFM Support Required';

} else {
return 0;
}
return 1;

View this message in context: http://requesttracker.8502.n7.nabble.com/Linking-a-Transaction-CF-value-to-a-Ticket-CF-value-tp54546p54593.html

I have now ran the trigger by replying to a ticket and setting the
'Alert_Support_T CF to ‘Alert’ and it produced the following error

Error Log

Unfortunately, you cut off the cause of this stack.
The line that comes after is unrelated.

It appears to be a mail sending error.

-kevin

Due to time constrains i have had to take a simpler approach to this issue
and go back to working with ticket obj instead of catching the details
dueing the transaction which i understand better at this point in time

i have created a new ticket CF (‘Alert_Support_Notes’) to store the users
comments when changing the ‘Alert_SUpport’ CF to ‘Alert’.

i have then added to scrips linked to the ‘Alert_Support’ CF

1/ when the ‘Alert_Support’ CF is set to ‘alert’ it wil check the new
‘Alert_Support_Notes’ CF for a comment, if there is no comment it will enter
in warning message and will email the last person to update the ticket
instructing them to add a comment

2/ when the ‘Alert_Support’ CF is set to ‘alert’ it will email our support
team to alert them that there is a ticket that requires there attention

3/ When the ‘Alert_Support’ CF is cleared it will also clear the
‘Alert_SUpport_Notes’ CF

than you for all your help Kevin

Scott

View this message in context: http://requesttracker.8502.n7.nabble.com/Linking-a-Transaction-CF-value-to-a-Ticket-CF-value-tp54546p54610.html