Professional Documents
Culture Documents
Parent-Child Relationship-Sample Implementation: 1. Purpose of The Document
Parent-Child Relationship-Sample Implementation: 1. Purpose of The Document
Parent-Child Relationship-Sample
Implementation
Table of Contents
The document outlines the need for the implementation of Parent-Child relationship and also the detailed
steps of its implementation using Custom Objects and other modules available in Oracle Service Cloud
product.
2. Problem Statement
In the current business requirements, there are cases when an object needs to be tied to one another in a
parent-child relationship, ie. An incident having many child incidents or an organization having multiple
child organizations, etc. In such cases, there should be a capability in the product to properly define the
parent-child relationship in an object. Also, the parent object might need to have a control on the other
child objects during any updates or for other workflows. Currently, there is no OOTB product functionality
available to have this business logic in place.
1
Parent-Child Relationship Implementation
3. Use Cases
4. Implementation
The extensibility framework of the product enables one to have the parent-child relationship implemented
in the objects and also satisfy all of the above listed use cases. Given below are the high level steps and
detailed steps on how to implement the parent-child relationship in the product using the currently
available product capabilities. “Incident” object has been considered here to show this sample
implementation.
Step 1 : Create a System Attribute “ParentIncident” which will serve as the placeholder for
Parent Incident’s Reference Number in all the Incidents
2
Parent-Child Relationship Implementation
8) Click on “Save”
9) Click on “Deploy” to deploy the newly created system attribute
10) Once deployed, the System Attribute “ParentIncident” will now be created under “Incident” object
3
Parent-Child Relationship Implementation
Step 2 : Create an “All_Incidents” Report – one-stop shop to view all the incidents with details
This report can be created by having “Incident Search” Report as Reference. Follow the steps given
below –
4
Parent-Child Relationship Implementation
14) The join expression in #11 implies that “incidents” table refers to “All Incidents” and “incidents2”
table refers to “Parent Incidents”
15) Choose the columns as needed from both the tables and click on “Save”
16) In order to select the run-time selectable filters for the report, under Home tab, click on “Data Set
View” under “Views”
17) The list of available Filters and Columns for the report will get displayed
18) To add additional filters, click on any one of the available filter column and click on “Add” under
“Design”
19) Include the additional filters such as “Subject”,”Parent Incident Reference Num”, “Incident
Reference Num” for the report
5
Parent-Child Relationship Implementation
Step 4 - Create a “ChildIncidentReport” to show the details of the child incidents for a given
Parent Incident
6
Parent-Child Relationship Implementation
Step 5 - Include a tab in the Incident workspace to show the related incidents
Step 6 - Make Changes in the “Incident Multi-Edit” Workspace to include “ParentIncident” field
7
Parent-Child Relationship Implementation
8
Parent-Child Relationship Implementation
Step 8 - Create a CPM script to update the status of the child Incidents when the status of the
Parent Incident is set to “Solved”
9
Parent-Child Relationship Implementation
10
Parent-Child Relationship Implementation
All the changes are now made to the workspace. You can test the changes by creating new incidents,
mapping the incidents to a parent incident and updating the status of the Parent incident.
<?
/**
Declare the name of this Object Event Handler:
* CPMObjectEventHandler: parentchildupdate
/**
* This class contains the implementation of the Object Event Handler.
11
Parent-Child Relationship Implementation
$parent_inc = RNCPHP\Incident::fetch($object->ID);
$parent_t_count = count($parent_inc->Threads);
while($roql_result = $roql_result_set->next())
{
while ($row = $roql_result->next())
{
$inc_tmp = RNCPHP\Incident::fetch($row[ID]);
$contact = RNCPHP\Contact::fetch($row[CID]);
$f_count = count($inc_tmp->Threads);
if($f_count == 0)
$inc_tmp->Threads= new RNCPHP\ThreadArray();
12
Parent-Child Relationship Implementation
$inc_tmp->save();
}
}
}
}
}
$object->save( RNCPHP\RNObject::SuppressAll );
return;
}
}
/**
* This class contains the test harness for the Object Event Handler.
* It must be the same name as declared above but with "_TestHarness"
* added as a suffix on the name.
*/
class parentchildupdate_TestHarness implements
RNCPM\ObjectEventHandler_TestHarness
{
/**
* setup() gives one a chance to do any kind of setup necessary
13
Parent-Child Relationship Implementation
* for the test. The implementation can be empty, but it must exist.
*/
public static function setup()
{
return;
}
/**
* fetchObject() is invoked by the test harness to get the set
* of objects to test with for the given action and object type.
* @param[in] $action may be one of:
* RNCPM\Action{Create,Update,Destroy}
*
* @param[in] $object_type is the PHP class name of the
* Connect object type being tested.
*
* \returns the object or an array of objects to test with.
*/
public static function fetchObject( $action, $object_type)
{
static $test_objs = array();
$md = $object_type::getMetadata();
switch ( $md->COM_type )
{
case 'Incident':
$obj->Subject = 'Test Incident Subject';
$obj->PrimaryContact = RNCPHP\Contact::fetch(1);
break;
default:
throw new \Exception( "Unexpected type: $object_type" );
}
switch ( $action )
{
case RNCPM\ActionUpdate:
$verb = 'update';
break;
}
$test_objs[$object_type] = $obj;
echo( "Invented " . $object_type::getMetadata()->COM_type . " for
$verb\n" );
14
Parent-Child Relationship Implementation
return( $obj );
}
/**
* validate() is invoked by the test harness to validate the
* expected effects of the given action upon the given object.
* Throw an exception or return false to indicate failure.
* @param[in] $action may be one of:
* RNCPM\Action{Create,Update,Destroy}
*
* @param[in] $object is the Connect for PHP object that was
* acted upon.
*
* \returns true if the test for $action, $object succeeded, or
* false otherwise.
* Throwing an exception is another way of communicating
* failure, and will display the exception text as a
* result of the test.
*/
public static function validate( $action, $object )
{
return true;
}
/**
* cleanup() gives one a chance to do any kind of post-test clean up
* that may be necessary.
* The implementation can be empty, but it must exist.
* Note that the test harness is integrated with the Connect API such
* that operations performed thru the Connect API are not committed,
* so there's no need to clean up after the test even if it has created,
* modified or destroyed objects via the Connect API.
*/
public static function cleanup()
{
return;
}
5. Appendix
-------
15