This is an old revision of the document!
Execution: Local with PHP
You could execute a workflow manually in your own vtigerCRM extension or PHP file.
You only need the following PHP Code:
require_once("<rootvtigerCRM_Url>/modules/Workflow2/run.php"); $current_user = new Users(); $current_user->id = <executingUserID>; $current_user = $current_user->retrieve_entity_info(<executingUserID>, "Users"); $objWorkflow = new WfMain(<workflowID>, false, $current_user); # If you have a recordID use: $newObj = Workflow_VTEntity::getForId("<recordID>"); # If you don't have a associated recordID and the workflow don't access fields you could use: # $newObj = Workflow_VTEntity::getDummy(); $newObj->loadEnvironment(array("variable" => "value", "variable2" => "value2")); // [optional] Variables, which will be available inside the Workflow in $env $objWorkflow->setContext($newObj); $objWorkflow->start();
Variables you need
<executingUserID> | UserID which is used for permissions (“1” = admin) |
<workflowID> | Which workflow you want to execute (ID you get from URL of the editor) |
<recordID> | Which record is associated with the execution (If no record, use the alternative with “getDummy()”) |