Invoke Custom Function from Workflow Task

This article will explain how to create a new custom function in workflow task. Follow steps below:

1. Prepare registration script (.php)

e.g.: vtiger_root/registerWFFunction.php

In order to register the function, this register file needs to be placed in your vtiger root directory, and then you manually need to call it from your browser:

Warning! You have to call this register file once. Everytime you call this register file, it will add the function to the vtiger_workflowtasks_entitymethod table in the database, so if you call it more than once then it will get added to the database more than once.

In this example we register handleSetEstimatedDate() custom function defined in include/EstimatedDateHandler.php file for Invoice module.

$adb = PearDatabase::getInstance();
$emm = new VTEntityMethodManager($adb);
    	$result = $adb->pquery("SELECT function_name FROM com_vtiger_workflowtasks_entitymethod WHERE module_name=? AND method_name=?", array('Invoice', 'SetEstimatedDate'));

2. Create Handler file

In another file we need define custom function and write content of this function.
e.g.: include/EstimatedDateHandler.php

function handleSetEstimatedDate($entityData) {

3. Invoke Custom function with module

Last step is create and run via browser this file.

$adb = PearDatabase::getInstance();
       $forModule = 'Invoice';
       $summary = 'set Estimate Date '.$forModule;
       $result = $adb->pquery("SELECT workflow_id FROM com_vtiger_workflows WHERE summary=? AND module_name=?", array($summary, $forModule));
           echo 'Create Workflow for '.$forModule.'!<br />';
           $wm = new VTWorkflowManager($adb);
           $wf = Settings_Workflows_Record_Model::getCleanInstance($moduleName);
   		$wf->description = $summary;
   		$wf->test = Zend_Json::encode(array());
   		$wf->moduleName = $forModule;
   		$wf->executionCondition = 3;
   		$wf->filtersavedinnew = 6;
           $adb->pquery('UPDATE com_vtiger_workflows SET type=? WHERE workflow_id=?',array('basic',$wf->id));
           $wfId = $wf->id;
       } else {
           $wfId = $adb->query_result($result,0,'workflow_id');
       $tResult = $adb->pquery("SELECT task_id FROM com_vtiger_workflowtasks WHERE workflow_id=?", array($wfId));
           $tm = new VTTaskManager($adb);
           echo 'Create Workflow Task for '.$forModule.'!<br />';
           $task = $tm->createTask('VTEntityMethodTask', $wfId);
           $task->active = true;
           $task->summary = "Estimated Date Handler";
           $task->methodName = "SetEstimatedDate";


Share this post

Comments (2)

  • Stefano Reply

    Hi, i need to create a custom function that create a new Project Task when a Service Contract status is completed.
    Can you help me?.

    January 14, 2020 at 8:55 am
    • Reply

      Hello, thank you for contacting us. This is more like customization needed for you. Please contact us at with your request. We will reply you with more details. Thanks

      January 14, 2020 at 9:19 am

Leave a Reply

Your email address will not be published. Required fields are marked *

Dear Vtiger Community, most of all our extensions are compatible with Vtiger 8.0 version.


We use cookies to improve our website. By browsing this website, you agree to our use of cookies. More info