Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:extensions:workflowdesigner:execute_workflows_from_php [2014/01/05 14:00]
swarnat
en:extensions:workflowdesigner:execute_workflows_from_php [2016/05/08 19:42] (current)
swarnat
Line 1: Line 1:
-====== Execution ​via PHP ======+====== Execution: Local with PHP ====== 
 + 
 +<WRAP center round tip 60%> 
 +2016-05-08: Updated to latest and easiest version 
 +</​WRAP>​
  
 You could execute a workflow manually in your own vtigerCRM extension or PHP file. You could execute a workflow manually in your own vtigerCRM extension or PHP file.
Line 5: Line 9:
  
 <code php> <code php>
-   ​$current_user = new Users(); +require_once(vglobal('​root_directory'​)."/​modules/​Workflow2/​autoload_wf.php");
-   ​$current_user->​id = <​executingUserID>; ​        +
-   ​$current_user = $current_user->​retrieve_entity_info(<​executingUserID>, ​"Users");+
  
-   $objWorkflow ​new WfMain(<​workflowID>,​ false, $current_user);+// The ID of the Workflow you want to execute 
 +$workflow_id ​1; 
 +// The userwhich 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;
  
-   # If you have a recordID use: +$wfExecuter ​new \Workflow\Execute(); 
-   $newObj ​Workflow_VTEntity::​getById("<​recordID>"​); +$wfExecuter->​setUser($executionUserId); 
-   # If you don't have a associated recordID and the workflow don't access fields you could use: +if(!empty($crmid)) { 
-   # ​$newObj = Workflow_VTEntity::​getDummy(); +   $wfExecuter->setRecord($crmid); 
-   ​ +}
-   $newObj->loadEnvironment(array("​asd"​ => "​asd"​));        // [optional] Variables, which will be available inside the Workflow in $env+
  
-   $objWorkflow->setContext($newObj); +// Set the $env Variable, which is initially available in Workflow 
-   ​$objWorkflow->start();+$wfExecuter->setEnvironment(array("​variable"​ => "​value",​ "​variable2"​ => "​value2"​));​ 
 + 
 +$wfExecuter->​runById($workflow_id); 
 + 
 +// If you have created your own trigger to execute multiple workflows, you could use the following function 
 +// Notice: Handling of configuration in Settings will be improved in future versions of Workflow Designer 
 +// $wfExecuter->runByTrigger("​TriggerKey"​);
 </​code>​ </​code>​
  
-| **<​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+