[rt-users] Form input interface

Gene LeDuc gleduc at mail.sdsu.edu
Tue Apr 17 15:02:25 EDT 2007


Here's the OnCreate scrip I use to create a DNS ticket from e-mail that is 
sent by a web form after a user fills it out.  The e-mail consists of 2 
lines.  The first is the string that I chose to use to separate the fields 
and the second line contains all the data separated by the string on the 
first line.  I did it this way so that I don't have to hard-code the 
separator into the scrip, it's provided by the e-mail.  I only log the last 
of the CF transactions because it's used to trigger another scrip.

Gene

### 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 $Content = $Transaction->Content;
my ($sep) = $Content =~ /(^.*$)/m;
chomp $sep;
$Content =~ s/\A$sep\n//s;
chomp $Content;
### At this point, =$sep contains my separator string and $Content contains 
the rest of the e-mail
#$RT::Logger->debug("$MyName: \$sep: '$sep'");
#$RT::Logger->debug("$MyName: \$Content: '$Content'");
my ($mName, $mIp, $mLoc, $mOs, $uName, $uPhone, $uEmail, $uDept, $uIp, 
$uAgent, $uComments) = split($sep, $Content);
set_custom('IP', $mIp);
set_custom('Location', $mLoc);
set_custom('OS', $mOs);
set_custom('User Name', $uName);
set_custom('Phone', $uPhone);
set_custom('E-Mail', $uEmail);
set_custom('Dept', $uDept);
set_custom('Comments', $uComments);
set_custom('User IP', $uIp);
set_custom('User Agent', $uAgent);
set_custom('Machine Name', $mName, 1);

### Sets custom field value
### set_custom($field_name, $field_value)
sub set_custom {
   my ($CFName, $CFValue, $record) = @_;
#$RT::Logger->debug("$MyName: set_custom($CFName, '$CFValue')");
   my $cf = RT::CustomField->new($CurrentUser);
   my ($id,$msg) = $cf->LoadByName(Name=>$CFName,);
   if (!$id) {
     $RT::Logger->debug("$MyName: Couldn't load CF ($CFName)");
     return undef;
   } else {
#    $RT::Logger->debug("$MyName: CF($CFName) loaded, id: " . $cf->id());
   }
   ($id, $msg) = $Ticket->AddCustomFieldValue
            (Field=>$cf, Value=>$CFValue, RecordTransaction=>$record ? 
$record : 0);
#  $RT::Logger->info("$MyName: CustomFieldValue ($CFName,$CFValue) added: 
$id $msg");
}


At 11:38 AM 4/17/2007, Kenneth Crocker wrote:
>Gene,
>
>
>         We don't want the user/requestor to use the web interface at all 
> for creating the ticket. Thanks.
>
>Kenn
>LBNL




More information about the rt-users mailing list