B2B Service Category Import Controller
<?php
namespace Custom\Controllers;
use \RightNow\Connect\v1_4 as RNCPHP;
class Import extends \RightNow\Controllers\Base
{
function __construct()
{
parent::__construct();
}
function categories(){
$context = RNCPHP\ConnectAPI::getCurrentContext();
$context->ApplicationContext = "Import Categories";
$data = 'Communications,Comment/Suggestion';
$data_parsed = explode(",", $data);
try{
$DisplayOrder = 0;
foreach($data_parsed as $row){
$DisplayOrder++;
$ServiceCategory = new RNCPHP\ServiceCategory();
$ServiceCategory->AdminVisibleInterfaces = new RNCPHP\NamedIDDeltaOptListArray();
$ServiceCategory->AdminVisibleInterfaces[0] = new RNCPHP\NamedIDDeltaOptList();
$ServiceCategory->AdminVisibleInterfaces[0]->ID = 1; //ID of the interface
$ServiceCategory->DisplayOrder = $DisplayOrder;//Display position relative to other dispositions with the same parent
$ServiceCategory->EndUserVisibleInterfaces = new RNCPHP\NamedIDDeltaOptListArray();
$ServiceCategory->EndUserVisibleInterfaces[0] = new RNCPHP\NamedIDDeltaOptList();
$ServiceCategory->EndUserVisibleInterfaces[0]->ID = 1; //ID of the interface
//It is a required field Array of names, one for each supported language
$ServiceCategory->Names = new RNCPHP\LabelRequiredArray();
$ServiceCategory->Names[0] = new RNCPHP\LabelRequired();
$ServiceCategory->Names[0]->LabelText = $row;
$ServiceCategory->Names[0]->Language = new RNCPHP\NamedIDOptList();
$ServiceCategory->Names[0]->Language->ID = 1;
$ServiceCategory->save(RNCPHP\RNObject::SuppressAll);
}
echo "<br><br>DONE.";
}
catch (RNCPHP\RNCPHPAPIError $err) {
echo($err->getCode() . "::" . $err->getMessage());
}
catch (\Exception $err) {
echo($err->getCode() . "::" . $err->getMessage());
}
}
}