From dc9d1bf1200065b9c34fd2aca4ebbfc642e22b52 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Thu, 20 Jul 2017 09:29:45 -0400 Subject: [PATCH] RT# 38517 - added auto create of customer contact, if requestor is not a contact yet when adding a company to ticket. --- rt/lib/RT/Interface/Web_Vendor.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm index ea3a498d6..da0b1892e 100644 --- a/rt/lib/RT/Interface/Web_Vendor.pm +++ b/rt/lib/RT/Interface/Web_Vendor.pm @@ -164,6 +164,33 @@ sub ProcessTicketCustomers { push @results, $msg; warn "$me: linking requestor to custnum $custnum: $msg\n" if $Debug > 1; + + ## check if FS contact email exists, if not create it. + if ( !qsearchs( { + 'table' => 'contact_email', + 'hashref' => { 'emailaddress' => $Requestor->{'values'}->{'emailaddress'}, }, + } ) ) { + use FS::contact; + + my $lname = $Requestor->{'values'}->{'realname'} ? + (split (/ /, $Requestor->{'values'}->{'realname'}))[-1] : + 'Requestor'; + + my $fname = $Requestor->{'values'}->{'realname'} ? + (split (/ /, $Requestor->{'values'}->{'realname'}))[0] : + 'RT'; + + my $contact = new FS::contact { + 'custnum' => $custnum, + 'first' => $fname, + 'last' => $lname, + 'emailaddress' => $Requestor->{'values'}->{'emailaddress'}, + 'comment' => 'Auto created from RT requestor', + }; + my $error = $contact->insert; + push @results, 'Created Freeside contact for requestor ' . $Requestor->{'values'}->{'emailaddress'} + unless $error; + } } } -- 2.11.0