[rt-users] Parsing Email Subject to insert into Custom Field
Kevin Falcone
falcone at bestpractical.com
Wed Oct 14 09:11:49 EDT 2009
On Wed, Oct 14, 2009 at 08:20:14AM -0400, Kevin Squire wrote:
> We have recently hired an outside company to be our "Tier-One" tech support. Every call they
> log sends us an email. We are filtering out the "Escalation" tickets and having those one
> added to our Helpdesk RT queue (Thanks to procmail). Now we need to parse the subject line of
> these Escalated tickets and pull out the "Tier-One" Call ID # and have that dumped into a
> custom field. My perl skills are limited to none, so I have tried to put together a few other
> scrips that I user and/or found to create one, but it is not working as I expect (it seems
> like it does nothing at all, either never applied, or is applied, but does not fill in the
> CustomField)... so I come to the exports to look over my work....
The RT-Extension-ExtractCustomFieldValues was designed for the parsing
part of your task, although you may need a little extra code to handle
the From checking.
If it isn't firing at all, you probably want to use RT::Logger in your
Preparation code
-kevin
> Every one of the incoming "Escalation" emails will have a set FROM and SUBJECT field....
> FROM: [1]tierone at foobar.com
> SUBJECT: FooBar Helpdesk Call - 1234567 - Escalation
>
> Condition: On Create
> Action: User Defined
> Template: Global template: Blank
> Stage: TransactionCreate
>
> ---------------------------------------------------------------------
> CUSTOM CONDITION
> ---------------------------------------------------------------------
> --left blank--
>
> ---------------------------------------------------------------------
> CUSTOM ACTION PREPARATION CODE
> ---------------------------------------------------------------------
> # Setup the check for the email address
> my $from_address = '[2]tierone at foobar.com';
>
> # Get who created this ticket and exit if it doesn't
> # match the system address from above
> my $requestor_address = lc($self->TicketObj->RequestorAddresses);
> if ($requestor_address ne $from_address) {
> ## Not from my company, so don't want to parse the subject line
> return 0;
> } else {
> return 1;
> }
>
> ---------------------------------------------------------------------
> CUSTOM ACTION CLEANUP CODE
> ---------------------------------------------------------------------
> ### Extract fields from e-mail
> ## my $MyName = "Scrip DNS:35:Commit (New Ticket)";
> my $Transaction = $self->TransactionObj;
> my $CurrentUser = $Transaction->CurrentUser;
> my $Ticket = $self->TicketObj;
> my $qNagme = 2;
> my $NewPri = 90;
> my $Content = $Ticket->Subject;
> # The seperator is
> my $sep = " - ";
> chomp $sep;
> $Content =~ s/\A$sep\n//s;
> chomp $Content;
> my ($issueCO, $issueID, $issueType) = split($sep, $Content);
> set_custom('Escalation_ID',$issueID, 0);
> # set_custom('Escalation_Type', $issueType, 0);
> # set_custom('Incoming_Co', $userCO, 0);
>
> ### Leave this until last, it triggers the ack e-mail to requestor
> $Ticket->SetPriority($NewPri);
>
> ### Sets custom field value
> ### Usage: set_custom($field_name, $field_value, $record_transaction)
> sub set_custom {
> my ($CFName, $CFValue, $record) = @_;
> my $cf = RT::CustomField->new($RT::SystemUser);
> my ($id,$msg) = $cf->LoadByName(Name=>$CFName,);
> if (!$id) {
> $RT::Logger->debug("$MyName: Couldn't load CF ($CFName)");
> return undef;
> }
> ($id, $msg) = $Ticket->AddCustomFieldValue
> (Field=>$cf, Value=>$CFValue, RecordTransaction=>$record ? $record : 0);
> }
>
> --
> [3]http://gentgeen.homelinux.org
>
> #############################################################
> Associate yourself with men of good quality if you esteem
> your own reputation; for 'tis better to be alone then in bad
> company. - George Washington, Rules of Civility
>
> References
>
> Visible links
> 1. mailto:tierone at foobar.com
> 2. mailto:tierone at foobar.com
> 3. http://gentgeen.homelinux.org/
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20091014/ad771af8/attachment.sig>
More information about the rt-users
mailing list