You're not currently signed in.

HomePage > Contributions > NotResolved

NotResolved

Summary

It's just a simple condition which looks to see if the ticket isn't marked as 'resolved'. But, as I managed to write it, with the help of the mailing list and the Wiki, I want to share it. And it could, maybe, help someone else to faster understand the way to use his own conditions.

The perl module

With the help of the 'local' mecanism you can customize RT to fit your needs and keep them along the updates. First you need to create a local directory for your own Conditions

$mkdir rt/local/lib/RT/Condition/

In this directory you could add all the conditions you will write. For example let's write one :

package RT::Condition::NotResolved; # declare our package name
use strict;
use base qw(RT::Condition::Generic);# nherit from generic
sub IsApplicable {                  # the method called by RT
  my $self = shift;
  my $ticket = $self->TicketObj;    # we are able to retrieve the ticket object
  if ($ticket->Status ne 'resolved')  { # we want to check if the ticket is resolved
      return(1);                    # if true, we can return 1, and the scrip action associated
                                    # will be executed
  }
  else {
      return(undef);                # if false, we don't want that the scrip action will be executed
  }
}
eval "require RT::Condition::NotResolved_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Condition/NotResolved_Vendor.pm});
eval "require RT::Condition::NotResolved_Local";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Condition/NotResolved_Local.pm});
1;

^^ I put the file here : rt/local/lib/RT/Condition/NotResolved.pm

Tell RT that we have a new scrip condition

Now we must inform RT that we have added a new scrip condition in order to let people use it. For this purpose we could use the RT::CLI.

$cat createNotResolvedCondition.pl
#!/home/rt/perl/bin/perl                 # change this to your perl installation path
use strict;
use Unicode::String qw(utf8 latin1);
# Replace this with your RT_LIB_PATH
use lib "/home/rt/rt/lib";
# Replace this with your RT_ETC_PATH
use lib "/home/rt/rt/etc";
use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );
use RT::ScripCondition;
##########################################################################
### RT CLI initialization
##
CleanEnv();
RT::LoadConfig();
RT::Init();
##Drop setgid permissions
RT::DropSetGIDPermissions();
##Get the current user all loaded
our $CurrentUser = GetCurrentUser();
unless( $CurrentUser->Id )
{
  print "No RT user found. Please consult your RT administrator.\n";
  exit 1;
}
###
### important code is below
###
my $sc = new RT::ScripCondition($CurrentUser); # instance an ScripConditionObject
$sc->Create(
           Name                 => "Lors d'une r�ponse � un ticket non r�solu", # short description
           Description          => "Lors d'une r�ponse � un ticket non r�solu", # long description
           ExecModule           => 'NotResolved',                               # name of our module
           ApplicableTransTypes => 'Correspond'                                 # the transaction type in which 
                                                                                # the condition will be called
           );

$sc->Create(
           Name                 => "Lors d'un commentaire � un ticket non r�solu",
           Description          => "Lors d'un commentaire � un ticket non r�solu",
           ExecModule           => 'NotResolved',
           ApplicableTransTypes => 'Comment'
           );

as you can see we can use the same module for different transaction type. Available transaction types are :

  • Any
  • Create
  • Correspond
  • Comment
  • Status
  • Set

We just need to execute the last script in order to update the RT Database :

$perl createNotResolvedCondition.pl

Problems

If you meet problem it may be necessary to copy some files into local directory :

$cp $RT/lib/RT/base.pm $RT/local/lib/RT
$cp $RT/lib/RT/Condition/Generic.pm $RT/local/lib/RT/Condition

Conclusion

Now you can simply use it directly from the web RT interface.

Thanks

I want to thanks all people that have help me to better understand RT.