At Sirius we're fans of Request Tracker, which is excellent free software for running a help desk. One reasonably common question on the Request Tracker user's mailing list is "how do I make setting a subject mandatory when creating a ticket?". Another useful modification that we use at Sirius is to force setting a non-zero priority on tickets.

RT is designed to be easily customised, and one way of achieving both of these features is to hook into Request Tracker's BeforeCreate callback. This callback gets called every time the "Create" button is pressed when creating a new ticket. If you haven't provided a callback the ticket is created as normal. If you have provided a callback, the chunk of code is executed, and the ticket creation can be postponed in the event of unacceptable input such as no subject.

Therefore we can force setting a mandatory subject using the following chunk of perl.

<%init>
my $ARGSRef = $ARGS{'ARGSRef'};

if ($$ARGSRef{'id'} eq 'new')
{
if ($$ARGSRef{'Subject'} !~ /^[a-zA-z0-9]+/)
{
my $msg = loc("You must set a subject, and the subject must start with a letter or number");
$RT::Logger->debug($msg);
push @$results, $msg;
$$skip_create = 1;
}

if ($$ARGSRef{'InitialPriority'} !~ /^([1-4]{1}|99)$/)
{
my $msg = loc("Initial priority must be 1, 2, 3 or 4");
$RT::Logger->debug($msg);
push @$results, $msg;
$$skip_create = 1;
}
}
</%init>
<%args>
$skip_create => undef;
$checks_failure => undef;
$results => undef;
</%args>

To install this into your RT installation, create a file containing the callback under:

share/html/Callbacks/Sirius_Callbacks/Ticket/Create.html/BeforeCreate

On Debian with Debian's RT packages, the full path is

/usr/share/request-tracker3.8/html/Callbacks/Sirius_Callbacks/Ticket/Create.html/BeforeCreate

(Naturally you don't have to use the directory "Sirius_Callbacks", it's an arbitrary name and doesn't need any configuration anywhere.)

It's advised to then clear out the Mason cache, and restart Apache. You will need to clear out the Mason cache if you modify the callback, for the changes to take effect.

Some things to note about the above code.

my $ARGSRef = $ARGS{'ARGSRef'};

gives us reference to several perl variables that will provide useful information in the callback, such as the provided subject and priority.

The variable $results is an array containing messages that should be displayed to the user to help them correct their invalid input.

The variable $skip_create is set to 1 (i.e. true) if invalid input is received, and thus RT knows not to not actually go ahead and create the ticket and display the contents of $results, instead.

A useful improvement would be to allow the regular expressions used to validate the subject and priority to be configured in the RT configuration file, if anybody has a solution, we will be glad to publish the results.

The end result, if you haven't provided the required information.

And if you have, the ticket will be created as normal.

beforecreate-rt

P.S. Thanks to Dominic Hargreaves for the comment: "Unless you're actually patching the Debian package, you shouldn't place your callbacks in /usr/share/request-tracker3.8/... but rather in /usr/local/share/request-tracker3.8/... which is there for just that purpose."