The Workflow Designer for VtigerCRM 6.x introduce a new process to integrate tasks you could use in your workflows.

Guided by the Linux Repositories I implement a Repository system to install/update new tasks.
So you will see any special tasks I provide and could install them manually with one click.

During Setup of the module

all available standard tasks will be installed. Some special task are marked not to install automatically, because they are mostly interact with external services, which not everybody needs.

During every Update of the module

all available task updates from my repositories are installed.
New tasks and tasks from external repositories won't installed/updated during module update.

Task Development

To create a new custom task you only need to go to the “Task Management” and press “create new Task manually”. The Workflow Designer will ask you some questions, how you would define the new task.

  1. The key
    This is the slug of the Block, which will be used to store the relation in the database. Must be unique!
  2. The classname
    Must be a value with the Prefix “WfTask”. For example WfTaskNewBlock. This is the classname of the new block.
  3. The label
    The label, visible in the sidebar and below every block. Should describe the function of this block.

Then the Workflow Designer will create the necessary files.
the block will create in the task group “special tools”.

Now you need to modify the files.

WfTask*.php

You found below /modules/Workflow2/tasks/.

This file must have a special structure.

<?php
require_once(realpath(dirname(__FILE__).'/../autoload_wf.php'));
 
class dummyTypeClass extends \Workflow\Task
{
    public function handleTask(&$context) {
        /* Insert here source code to execute the task */
 
        return "yes";
    }
 
    public function beforeGetTaskform($viewer) {
        /* Insert here source code to create custom configurations pages */
    }
    public function beforeSave(&$values) {
        /* Insert here source code to modify the values the user submit on configuration */
    }
}

The require_once will make sure all Workflow related functions are available.
This line is important, because later I will make sure you could call every type externally.

handleTask(&$context)

This function will be executed every time the task will be executed and must include all php code you want to run in this situation. (But you could also include external files like in every other php script)
This function MUST have a return value, which is equal to one of the output points you configure in task.xml.
The parameter is from the Type \Workflow\VTEntity, which will be explained Here.

beforeGetTaskform($viewer)

This function will be called before the configuration popup is shown. You could prepare all dependencies and assign values to the $viewer parameter, which is the Smarty Object used for the popup.

beforeSave(&$values) This function will be called before the configuration values are saved. The $values variable is an array with the submitted fields in the task variable.

WfTask*.js

You found below /modules/Workflow2/tasks/.

Will be loaded in the configuration popup and could handle all functions for this window.

WfTask*.tpl

You found below /layouts/vlayout/modules/Settings/Workflow2/tasksforms/
The wildcard will be replaced by the task key for this file and not the classname.

The configuration template.
There exists an open <form Tag, which will store any value you write to the task[…] variable and give this value also back to the template.

Enter your comment. Wiki syntax is allowed:
  ____      __   __   _      __   ___ 
 / __ \ __ / /  / /  | | /| / /  / _ \
/ /_/ // // /  / /__ | |/ |/ /  / , _/
\___\_\\___/  /____/ |__/|__/  /_/|_|