Skip Navigation
Expand
Anatomy of a CPM (Custom Process)
Answer ID 10086   |   Last Review Date 06/25/2024

What are the main components of a Custom Process (CPM)?

Environment:

Process Designer, Custom Process Model (CPM), Service Process Model (SPM)
All product versions

Resolution:

There are three main components of a Custom Process (or Object Event Handler):

1. The header:

/*
* CPMObjectEventHandler: demo
* Package: OracleServiceCloud
* Objects: Contact, CO\TestCustomObject
* Actions: Create, Update
* Version: 1.4
*/

- the header is required, even though it is commented
- it will be read and used by the runtime
- it contains information on the objects and actions supported by the script
- the CPMObjectEventHandler name must match the class name and the test harness class (see examples below)

2. The implementation

- contains the required custom business logic to manipulate objects that are passed in at runtime
- the apply() method does most of the work
- the API version must match the one specified in the header
- the class name must match the name specified in the header
- the apply() function has 4 parameters: $run_mode (indicates if the script is running in a test harness or in production - 1 for production/live mode, 2 for tests run from Process Designer), $action (the event that triggered the execution - create, update or destroy), $object - the object executed on (e.g. Incident), $n_cycles (the number of execution loops the script has entered)
- sample:

use \RightNow\Connect\v1_4 as RNCPHP;
use \RightNow\CPM\v1 as RNCPM;
 
class demo implements RNCPM\ObjectEventHandler {
    
public static function apply($run_mode, $action, $obj, $n_cycles){ 
    switch($action) {
    case RNCPM\ActionCreate:
        $verb="created";
        break;
    case RNCPM\ActionUpdate:
        $verb="updated";
        break;
    }
}
}

3. The test harness

- contains the required self-testing code
- the name of the class must be the CPM name, underscore, TestHarness
- the setup() function may instantiate helper objects used in the test
- the fetchObject function creates/returns an object to be tested, which is then passed through the apply() function during the test
- the validate() function checks to see if the results of the apply() execution are as expected. Messages can be printed here using echo
- the cleanup() function can remove any objects created in the test
- sample:

class demo_TestHarness implements RNCPM\ObjectEventHandler_TestHarness {
    public static function setup(){
        return;
    }
    public static function fetchObject($action, $object_type){
        $contact=$object_type::first('ID > 0');
        echo "Fetched Contact ID ".$contact->ID;
        return($contact);
    }
    public static function validate($action, $object){
        $pass=true;
        return($pass);
    }
    public static function cleanup(){    
        return;
    }
}

 

For more information please review the ConnectPHP documentation: