This is an old revision of the document!


Execution: Local with PHP

DEPRECATED. Will be renewed.

You could execute a workflow manually in your own vtigerCRM extension or PHP file.
You only need the following PHP Code:

   global $root_directory;
   require_once($root_directory."/modules/Workflow2/autoload_wf.php");
 
        // The ID of the Workflow
        $workflow_id = 1;
        // The user, which will be used for execution
        $executionUserId = 1;
        // Specify a CRMID if you want to execute the record in context of this record. (Important for field values)
        $crmid = false;
 
        $wfExecuter = new \Workflow\Execute();
        $wfExecuter->setUser($executionUserId);
        if(!empty($crmid)) {
            $wfExecuter->setRecord($crmid);
        }
 
// Set the $env Variable, which is initially available in Workflow
        $wfExecuter->setEnvironment(array("variable" => "value", "variable2" => "value2"));
 
        $wfExecuter->runById($workflow_id);
 
        // If you have created your own trigger, you could use the function
        // Handling of configuration in Settings will be improved in future versions of Workflow Designer
        $wfExecuter->runByTrigger("TriggerKey");