Documentation > WriteCustomCondition
How to write custom condition code
Introduction
Scrips' condition is a code that checks if that current transaction/ticket match some condition(s) and says to RT to run or skip scrip action.
Basic
When you write a custom condition you have access to the same objects as scrip action has, so its worth it to read basics section of WriteCustomAction article.
Major objects accessors are:
$self->TransactionObj # returns the current transaction object $self->TicketObj # returns the current ticket object $self->TemplateObj # returns the current template object
Then you can have more details on available methods with
perldoc /opt/rt3/lib/RT/Ticket.pm perldoc /opt/rt3/lib/RT/Ticket_Overlay.pm perldoc /opt/rt3/lib/RT/Tickets.pm perldoc /opt/rt3/lib/RT/Tickets_Overlay.pm perldoc /opt/rt3/lib/RT/Transaction.pm perldoc /opt/rt3/lib/RT/Transaction_Overlay.pm perldoc /opt/rt3/lib/RT/Transactions.pm perldoc /opt/rt3/lib/RT/Transactions_Overlay.pm
Return values
Whatever the test you do in your condition, you just have to return true value (like 1)
on success or false (like 0 or undef) to abort the scrip action. Below a very simple
condition that you can copy to the RT web interface if you choose User Defined
condition when you create a new scrip condition:
# get ticket object my $ticket = $self->TicketObj; # don't do anything if ticket is resolved return 0 if $ticket->Status eq 'resolved'; # otherwise run scrip action return 1;
Transaction
Transaction object is most used object in conditions as it describes what's happened with the ticket just a few ticks ago.
Most important properies of the transaction object are Type and Field.
Another way to add conditions to RT
See NotResolved for another way of adding Conditions to RT