Skip Navigation
Expand
Returning previous values for fields/objects in Custom Processes
Answer ID 8880   |   Last Review Date 06/16/2021

What are the constraints that could ensure/prevent previous object values from being retrieved using "prev" in Custom Processes?

Environment:

Connect PHP API

Resolution:

Previous values retrieved using "->prev" are not set if an asynchronous custom process is involved, by design. In order for previous values to be available, the custom process would have to be synchronous.

Also, previous values are not available on fetched objects (objects obtained using the API fetch function). For previous values to be available in a synchronous CPM, the object reference passed in the CPM apply function must be used. This applies to code placed in the CPM Test Harness class, including the object passed in the main CPM class apply function.

Keep in mind that unlike their asynchronous version, synchronous custom processes have an execution time limit of 5 seconds. Further, code for this should handle cases where the previous value is null such as in the following example:

if (isset($obj))
{
	if (isset($obj->prev))
	{
		if (isset($obj->prev->CustomFields->c->fieldName))
		{
			$clminfoprev=$obj->prev->CustomFields->c->fieldName;
		}
	}
}

 

You can find more information about the two types of execution for custom processes in the following knowledge base article:
Answer ID 6604: There are two types of execution for Object Event Handlers

Additional information can be found in the ConnectPHP documentation:
Answer ID 5169: Technical Documentation and Sample Code