[Vtigercrm-developers] FWD: How to create a custom workflow function.

Alan Lord alanslists at gmail.com
Fri Jan 29 08:22:07 GMT 2016


On 28/01/16 20:15, Bernard Bailey wrote:
>
> I digress; I need some assistance to create a custom workflow function.
>
> Where to start?

It really is quite easy...

There are two parts to it:

The first is to write your function like any other normal php function. 
The file can go anywhere you like within the vtiger structure but I tend 
to create a file called something like ModuleNameWFHandler.php (WF to 
indicate Workflows rather than the Event Handler API) and stick it in a 
"resources" directory of the module in question which is "triggering" 
the workflow.

The function itself is passed an entity object when it is triggered,

> function CreateNewDealer($entity) {
> 	global $adb, $log;
> 	$log->debug("Entering Custom Workflow Function: " . __FUNCTION__);

> 	/* DEBUG ONLY - USE THIS TO DISPLAY $entity
> 	$entityArray = get_object_vars($entity);
> 	echo '<pre>';
> 	print_r($entityArray);
> 	echo '</pre>';
> 	die;
> 	*/
.... you code here

>    	$log->debug("Exiting Custom Workflow Function: " . __FUNCTION__);
> }



Then you can carry on and write your function to do what it is you 
need... (Hint, really try and use the Server API rather than direct 
database queries, especially if they are INSERTs...)

Once your workflow function is ready to test, you need to register it in 
the vtiger database so it is visible when you choose the Custom Task in 
the Workflow...

Here is an example of a script you can run from the command line at the 
root of the vtiger directory:

http://paste.ubuntu.com/14694132/

Hope that helps.

Al




More information about the vtigercrm-developers mailing list