$ 0 0 Topic by Larry EdwardsCode Block<? /* * CPMObjectEventHandler: incident_create_handler * Package: RN * Objects: Incident * Actions: Create * Version: 1.3 * Description: Used for when incidents get created in CHARM interface == 4 to switch to either LaneBryant (default) or Catherines. Can remove once Charm interface is removed */ use \RightNow\Connect\v1_3 as RNCPHP; use \RightNow\CPM\v1 as RNCPM; class incident_create_handler implements RNCPM\ObjectEventHandler { public static function apply($run_mode, $action, $obj, $n_cycles) { $Interface1 = 3; $Interface2 = 5; $selectedProduct = $obj->Product->ID; $refNo = $obj->ReferenceNumber; $debug = true; $changeInterfaceTO = $Interface1; //use as DEFAULT if($debug) echo "REFNO: $refNo Selected SITE interface ID is " . $obj->Interface->ID . "<br>"; if($obj->Interface->ID == 4) { try { if($selectedProduct == 5) { $changeInterfaceTO = $Interface2 ; } if($debug) echo "REFNO: $refNo selected product is $selectedProduct so setting interface to $changeInterfaceTO <br>"; /* THIS CODE DOESNT THROW ERROR BUT ALSO DOESNT DO ANYTHING if(!$obj->SiteInterface) $obj->SiteInterface = new RNCPHP\NamedIDLabel(); $obj->SiteInterface->ID = intval($changeInterfaceTO); */ $obj->Interface->ID = intval($changeInterfaceTO); $obj->save(RNCPHP\RNObject::SuppressAll); return; } catch (Exception $e) { if($debug) echo "ConnectPHP error: " . $e->getMessage(); throw new RNCPM\CPMException("ConnectPHP error: " . $e->getMessage(), 1, 0);; } }//end check if interface is CHARM == 4 } } class incident_create_handler_TestHarness implements RNCPM\ObjectEventHandler_TestHarness { static $obj_invented = NULL; public static function setup() { $IntDefault = 4; $lbInt = 3; $cathInt = 5; $selectObject = RNCPHP\Incident::fetch(4417753); //RNCPHP\ROQL::queryObject("SELECT Incident FROM Incident where ID = 4417753")->next()->next(); if(!$selectObject->ID && ! $selectObject->ID > 0) { //Query failed so create manual $selectObject = new RNCPHP\Incident(); $selectObject->Subject = "TEST CPM"; $selectObject->SiteInterface = new RNCPHP\NamedIDLabel(); $selectObject->SiteInterface->ID = $IntDefault ; $selectObject->Product = RNCPHP\ServiceProduct::fetch(4);//4 is 5 is $selectObject->Category = RNCPHP\ServiceCategory::fetch(97);//just order inquiry $selectObject->Threads = new RNCPHP\ThreadArray(); $selectObject->Threads[0] = new RNCPHP\Thread(); $selectObject->Threads[0]->EntryType = new RNCPHP\NamedIDOptList(); $selectObject->Threads[0]->EntryType->ID = 3; // Used the ID here. See the Thread object for definition $selectObject->Threads[0]->Text = "TEST OF NEW INCIDENT FOR CPM."; $selectObject->PrimaryContact = RNCPHP\Contact::fetch(1604935);//Required field to create an incident through connect PHP --> Larryedwards@helixmail.com $selectObject->save(RNCPHP\RNObject::SuppressAll); } static::$obj_invented = $selectObject; return; } public static function fetchObject($action, $object_type) { return(static::$obj_invented); } public static function validate($action, $object) { return true; } public static function cleanup() { return; } }Image