Difference between revisions of "WriteCustomCondition"

From Request Tracker Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by 3 users not shown)
Line 12: Line 12:


Major objects accessors are:
Major objects accessors are:
 
<pre>
  $self-&gt;TransactionObj # returns the current transaction object
  $self-&gt;TransactionObj # returns the current transaction object
  $self-&gt;TicketObj      # returns the current ticket object
  $self-&gt;TicketObj      # returns the current ticket object
  $self-&gt;TemplateObj    # returns the current template object
  $self-&gt;TemplateObj    # returns the current template object
</pre>


== Return value ==
== Return value ==
Line 21: Line 22:
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 <code>User Defined</code> condition when you create a new scrip condition:
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 <code>User Defined</code> condition when you create a new scrip condition:


  <nowiki># get ticket object
  <pre>
# get ticket object
  my $ticket = $self-&gt;TicketObj;
  my $ticket = $self-&gt;TicketObj;
  # don't do anything if ticket is resolved
  # don't do anything if ticket is resolved
Line 27: Line 29:
  # otherwise run scrip action
  # otherwise run scrip action
  return 1;
  return 1;
  </nowiki>
  </pre>


== Transaction ==
== Transaction ==
Line 33: Line 35:
Transaction object is most used object in conditions as it describes what's happened with the ticket just a few ticks ago.
Transaction object is most used object in conditions as it describes what's happened with the ticket just a few ticks ago.


Most important properties of the transaction object are <code>Type</code> and <code>Field</code>.
Most important properties of the transaction object are <code>Type</code> and <code>Field</code>. More on [[Transaction]].
 
More on [[Transaction]].


== Another way to add conditions to RT ==
== Another way to add conditions to RT ==

Latest revision as of 08:54, 25 July 2016

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

Return value

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 properties of the transaction object are Type and Field. More on Transaction.

Another way to add conditions to RT

See NotResolved for another way of adding Conditions to RT

Further readings

CustomConditionSnippets, WriteCustomAction, ScripAction