First of all I would like to apolagize in advance if this topic is discussed somewhere else. If it is, please point me in that direction. Thank you.
Ok, so we are trying to create ticket from a php web page using the following code bellow:
Code: Select all
<?php
$otrs_title = "TEST_";
$otrs_subject = "TEST_";
$otrs_queue = "Raw";
$otrs_from = "some_email";
$otrs_email = "another_email";
$otrs_user = "soap_user";
$otrs_pass = "soap_password";
$otrs_url = "http://our_otrs_installment_link/otrs/rpc.pl";
$in_customerid = 4;
$in_customeruser = "some_other_email";
$in_owner = 3;
$soapclient = new SoapClient(null, array('location' => $otrs_url,
'uri' => "Core",
'trace' => 1,
'login' => $otrs_user,
'password' => $otrs_pass,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED));
# creating a ticket number
$ticketnr = $soapclient->__soapCall("Dispatch", array($otrs_user, $otrs_pass, "TicketObject", "TicketCreateNumber"));
#php changes long numbers to 123E+10 notation to prevent this screwing up our ticketnumbers we convert notation
#it into normal plain numbers. but only if not string,because sometimes you have a string addition like XY123 on your
#ticket numbers
if(! is_string($ticketnr) ) $ticketnr = number_format($ticketnr,0, '.', '');
// # create the new ticket
$otrs_userid = $soapclient->__soapCall("Dispatch", array($otrs_user, $otrs_pass, "UserObject", "UserLookup", "UserLogin", $in_owner));
$ticketid = $soapclient->__soapCall("Dispatch", array($otrs_user, $otrs_pass, "TicketObject", "TicketCreate",
"TN", $ticketnr,
"Title", $otrs_title,
"Queue", $otrs_queue,
"Lock" , "unlock",
"PriorityID", 3,
"State" , "new",
"CustomerId", $in_customerid,
"CustomerUser", $in_customeruser,
"OwnerID", $otrs_userid,
"UserID", $otrs_userid));
$articleid = $soapclient->__soapCall("Dispatch", array($otrs_user, $otrs_pass, "TicketObject", "ArticleSend",
"TicketID" , $ticketid,
"ArticleType" , "email-external", # email-external|email-internal|phone|fax|...
"SenderType" , "agent", #agent|system|customer
"From" , $otrs_from,
"To" , $otrs_email,
"Subject" , "[Ticket#".$ticketnr."] ".$otrs_subject,
"Body" , "HAULES",
"ContentType" , "text/plain; charset=utf-8",
"Charset" , "utf-8",
"HistoryType" , "EmailCustomer", #EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...
"HistoryComment" , "generated by OTRSInterface-Class",
"UserID" , $otrs_userid,
"NoAgentNotify" , 1, # if you don't want to send agent notifications
"MimeType" , "text/plain",
"Loop" , 0 # auto reject|auto follow up|auto follow up|auto remove));
$linkid = $soapclient->__soapCall("Dispatch", array($otrs_user, $otrs_pass, "LinkObject", "LinkAdd",
"SourceObject", "Ticket",
"SourceKey", "0601158", #0601158 is the tn of a pre-existing ticket to link to.
"TargetObject", "Ticket",
"TargetKey" , $ticketid,
"Type", "ParentChild",
"Direction", "Target",
"State" , "Valid",
"UserId", $otrs_userid));
echo "$ticketnr";
echo "<br>";
echo "$ticketid";
?>
The strange behaviour I noticed is that the ticket number keeps incrementing itself. And I also created a ticket from the OTRs web interface and the ticket number it took was exactly the next number in line from the ticket number the script printed. (e.g: the scripts prints 1000047, the ticket number of the ticket created in OTRs has 1000048).
What am I missing here ? Do I need to run an extra script ? Is the script wrong ? Any help would be great.
PS: OTRs version is 3.1.4. SOAP module is enabled and so are the username and password in SysConfig Core::SOAP
Thank you and regards,
Sorin M.