Oracle Service Cloud RightnowCX Custom Controller: Lookup Contact, Create Incident


<?php

namespace Custom\Controllers;

/************* Agent Authentication ***************/
require_once( get_cfg_var("doc_root")."/ConnectPHP/Connect_init.php" );
initConnectAPI();

use RightNow\Connect\v1_2 as RNCPHP;

class GSChatIncident extends \RightNow\Controllers\Base
{

function __construct()
{
parent::__construct();
}

public function createContactIncident() {

try{
\RightNow\Libraries\AbuseDetection::check();

//$incident->SiteInterface = new RNCPHP\NamedIDLabel();
//$incident->SiteInterface->ID = 111;

$email = $_POST['email'];
$cID = (int)$_POST['countryID'];
$languageID = (int)$_POST['langID'];

$CI = &get_instance();
$contactmodelobj=$CI->load->model('standard/Contact_model');

$found = $this->Contact_model->lookupContactByEmail($email, null, null)->result;

if($found != null && is_int($found) && $found != false){
$creatingContact = $found;
} else {
$creatingContact = 1;
}

$incident = new RNCPHP\Incident();
$incident->Subject = "Chat cancelled";
$incident->CustomFields->c->system_source->ID = 2156;
$incident->CustomFields->c->country = new RNCPHP\NamedIDLabel();
$incident->CustomFields->c->country = $cID;
$incident->Language = $languageID;
$incident->PrimaryContact = RNCPHP\Contact::fetch($creatingContact); //Required field to create an incident through connect PHP
$incident->save(RNCPHP\RNObject::SuppressAll);
}

catch (Exception $err ){
echo $err->getMessage();
}
}
}
?>

Leave a Reply

You must be logged in to post a comment.