[rt-users] setting the Due Date upon ticket creation ... REVISITIED reg exp how to howto

Ennis William McCaffrey ennis at mail.twcgb.net
Fri Jul 29 09:52:27 EDT 2005


Ruslan, Michael:

I have the scrip working fine, and wanted to share my information with the 
mailing list (see below). I also want to say thank you to both of you for your 
efforts in pointing me in the right direction!

$RT::Logger->debug("begin Script 175");

my $AttachObj = $self->TransactionObj->Attachments->First;

my $content = $AttachObj->Content;

$RT::Logger->debug("Just before if statement Script 175");
if( $content =~ m/^Set-Start(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})$/m ) {
        $RT::Logger->debug("Within if statement of Script 175");
        $self->TicketObj->SetStarts( "$1" );
}
$RT::Logger->debug("Just after if statement Script 175");

$RT::Logger->debug("Just before clean line Script 175");

# strip special commands from email content
$content =~ s/^Set-Start(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})$//gm;

$RT::Logger->debug("Just after clean line Script 175");

$RT::Logger->debug("Just before replace content Script 175");

# silently overwrite attachment content
$AttachObj->__Set( Field => 'Content', Value => $content );

$RT::Logger->debug("Just after replace content Script 175");

$RT::Logger->debug("end Script 175");

return 1;


Explanation:

1) the key is in the regular expression

   m/^Set-Start(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})$/m
   
2) m/ /m  simply defines the search string

3) ^Set-Start  identifies the beginning of line to search for

4) \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2} 
   identifies the actual date format to search for
   
5) the ()'s around the date format tell Perl that if it finds a match
   then to save this matching string into variable $1
    
6) $self->TicketObj->SetStarts( "$1" ) sets the start date to the match
   Perl found above and placed into varuable $1
     
7) $content = ~s/^Set-Start(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})$//gm; 
   This line substitutes a blank (signified by the // near the end of the line)
   for the matching regular expression. The /s at the beginning tells Perl
   to substitute and not just to search.    
   
8) I found the following web site helpful, and many thanks to the author(s).  
   http://www.sstcommunications.com/docs/catalog/perlre.html 
   
9) I also found the book "Learning Perl" by R. L. Schwartz and T. Phoenix to
   be extermely useful as well. ( also thanks to the authors)

10) The debugging statements may be taken out when the scrip is complete.

11)  There is one final hurdle to clear here, however. That is, RT's internal 
     clock is set to GMT, so you must migrate your dates to GMT before inserting
     them into the database. I do this outside of , via a PHP 
     function/subroutine.
     
Good luck!
     
Ennis McCaffrey

Time Warner Cable
Digital Network Engineer

1001 West Kennedy Avenue
PO Box 145
Kimberly, WI 54136

(920) 831-9220 Office
(920) 378-0416 Cell

Ennis at Mail.TWCGB.NET




More information about the rt-users mailing list