This is an old revision of the document!


If you are a PHP developer you could extend the Workflow Designer on lot's of interfaces.
I implement lot's of these interfaces only for the 6.x version. If you are still using 5.4, you probably don't found the directories to create files.

The most important fact for your should be: Don't modify any files created by the core Workflow Designer.
This files will be overwritten with every update and your modifications are lost.

All already existing core extension files, are installed in plain PHP code and not be encrypted!

Add functions you could use in custom expressions

This is the only interface existing also in the 5.4.0 version.

Sometimes you want to integrate a function which will too big to integrate in a simple text field.
For this you should create your own PHP functions.

In VtigerCRM 5.4: Create a new file inside modules/Workflow2/functions/ with the filename <individual>.inc.php In VtigerCRM 6.x: Create a new file inside modules/Workflow2/extends/functions/ with the filename <individual>.inc.php

All functions with the nameprefix wf_ you define in this file, will be available during custom expressions.

Don't modify the core.inc.php File. There are the functions defined, which already come with Workflow Designer. But you could use this file as example, how your file should be build.

If you break the PHP Syntax and integrate an Error in this file, no Workflow could be executed, because this files are included in most tasks!

Example, which is currently integrated in Core:

if(!function_exists("wf_date")) {
    function wf_date($value, $interval, $format = "Y-m-d") {
        if(empty($interval)) {
            $dateValue = strtotime($value);
        } else {
            $dateValue = strtotime($interval, strtotime($value));
        }
 
        return date($format, $dateValue);
    }
}

You have a module, which create files you want to integrate into Workflows?

PDFMaker and SQLReports are implemented in this way!

Only VtigerCRM 6.x

If you create a similar module you could create a interfacefile to attach this files to Mails, Store as Documents or simple use the file in every task, which could handle files in any way.

Create a files in modules/Workflow2/extends/interfaceFiles/ with the filename <individual>.inc.php.

This file must include a Class, which extends from \Workflow\InterfaceFiles.
You must implement the following structure to be recognized by Workflow Designer:

<?php
namespace Workflow\Plugins\InterfaceFiles;
 
class [ModuleName] extends \Workflow\InterfaceFiles {
    protected $title = '[ModuleName]';
    protected $key = '[SanitizedModuleName]';
 
    public function __construct() {
        if(!$this->isModuleActive()) {
            return;
        }
    }
 
    /**
     * @var String $moduleName The module of the current Workflow
     * @return array -  array(
     *                   'filekeyA' => 'File title of the first file from this module',
     *                    ...
     *                  )
     *
     *      The file title will be shown in the task configurations.
     *      The filekey will be given to your _getFile and should uniquely identify the file you should generate
     */
    protected function _getAvailableFiles($moduleName) {
        $return = array();
        if(!$this->isModuleActive()) {
            return $return;
        }
 
        /*
          This function must simple return an array, like this:
             array(
                'filekeyA' => 'File title of this file'
             )
 
        */
 
        return $return;
    }
 
    /**
     * @var String $key - The fileKey you set in the _getAvailableFiles function
     * @var String $moduleName - The module from the given RecordID, which should be used to generate the file
     * @var Int $crmid - The ID of the Record, which should be used to generate the file
     * @return array - An Array with the following Structure
     *                  array(
     *                      'path' => "<temporarily path to the generated file>",
     *                      'type' => "<mime type of the generated file>",
     *                      'name' => "<filename of the generated file>"
     *                  );
     * The filename will probably overwritten by some tasks,
     * but if not, it will be used to give this file to the user.
     */
    protected function _getFile($key, $moduleName, $crmid) {
        if(!$this->isModuleActive()) {
            return false;
        }
 
        return array(
            'path' => "<temporarily path to the generated file>",
            'type' => "<mime type of the generated file>",
            'name' => "<filename of the generated file>"
        );
    }
 
    public function isModuleActive() {
        return getTabid('[moduleName]') && vtlib_isModuleActive('[moduleName]');
    }
}
 
// This will register this class in the Interface Registry
\Workflow\InterfaceFiles::register('[SanitizedModuleName]', '\Workflow\Plugins\InterfaceFiles\[ModuleName]');

Add new Options what to do with Files generated by Workflows

With 600.0801 in added this interface. It will be integrated in every tasks in the next versions. At this moment it is only integrated into the new PDFMaker Integration block.

Add a file in /modules/Workflow2/extends/fileactions/ with the filename “<individual>.inc.php

This file must contain a class which extends from \Workflow\FileAction. This class must have the following structure:

<?php
namespace Workflow\Plugins\FileActions;
 
class [IndividualNameA] extends \Workflow\FileAction {
 
    /**
     * @param String $moduleName - The module from the workflow, this action will be used
     * @return array - Returns an array with the Option, this file could provide:
     *                  array(
                             'title' => '<title of this FileAction (could be translated in lang Files)>',
                             'options' => $options
                        )
 
                        $options is also an array with configuration options,
                                 the User should input, if he choose this action
                        $options = array(
                              '<configKeyA>' => array(
                                  'type' => '<templatefield|templatearea|picklist|checkbox>',
                                  'label' => '<label show before this configuration option (could be translated)',
                                  'placeholder' => '<placeholder of input field>,
                                    // if type = checkbox
                                    //  'value' => 1
                                    // if type = picklist
                                    //  'options' => array('ID1' => 'value1', 'ID2' => 'value2', ...)
                              ),
                              ...
                          )
     */
    public function getActions($moduleName) {
        $return = array();
 
        return $return;
    }
 
    /**
     * @param array $configuration - Array with all configuration options, the user configure
     * @param string $filepath  - The temporarily filepath of the file, which should be transformed
     * @param string $filename  - The filename of this file
     * @param \Workflow\VTEntity $context - The Context of the Workflow
     * @param array $targetRecordIds
     * @return void
     */
    public function doAction($configuration, $filepath, $filename, $context, $targetRecordIds = array()) {
 
    }
 
}
 
\Workflow\FileAction::register('[SanitizedIndividualNameA]', '\Workflow\Plugins\FileActions\[IndividualNameA]');

Add a FieldType for Request Values from User

You would like to request a very special value from your users and you couldn't do this with the integrated field types? You could integrate you own fieldtypes!

Add a file in /modules/Workflow2/extends/fieldtypes/ with the filename “<individual>.inc.php

This file must contain a class which extends from \Workflow\Fieldtype. This class must have the following structure:

<?php
namespace Workflow\Plugins\Fieldtypes;
 
class [IndividualNameA] extends \Workflow\Fieldtype
{
    /**
     * Should return every fieldtype this class will provide
     *
     * @param $moduleName - The moduleName of the Workflow, which include this field
     * @return array - An Array with the following Structure
     *                  array(
     *                      array(
                                'id' => '<uniqueFieldTypeID>',
                                'title' => '<NameOfFieldType>',
                                'config' => $config
     *                      ), ...
     *                  )
                    $config is an array of configuration fields, the admin needs to configure in backend
     *                      it must have the following structure
     *                      array(
     *                          '<configKey>' => array(
                                    'type' => '[templatefield,templatearea,picklist,checkbox]',
     *                              'label' => '<label Of Configuration Input>',
                                     // if type = checkbox
                                     // 'value' => 1
                                     // if type = picklist
                                     // 'options' => array('ID1' => 'value1', 'ID2' => 'value2', ...)
     *                          ), ...
     *                      )
     *
     */
    public function getFieldTypes($moduleName) {
        $fields = array();
 
/*
Example:
        $fields[] = array(
            'id' => 'reference',
            'title' => 'Referenz',
            'config' => array(
                'reference' => array(
                    'type' => 'picklist',
                    'label' => 'Referenz',
                    'options' => $relmodules,
                )
            )
        );
*/
 
        return $fields;
    }
 
 
    /**
     * @param $data     - Config Array of this Input with the following Structure
     *                      array(
     *                          'label' => 'Label the Function should use',
     *                          'name' => 'The Fieldname, which should used as name attribute',
     *                          'config' => Key-Value Array with all configurations, done by admin
     *                      )
     * @param \Workflow\VTEntity $context - Current Record, which is assigned to the Workflow
     * @return array - The rendered content, shown to the user with the following structure
     *                  array(
     *                      'html' => '<htmlContentOfThisInputField>',
     *                      'javascript' => 'A Javascript executed after html is shown'
     *                  )
     *
     */
    public function renderFrontend($data, $context) {
        $html = '';
        $script = '';
 
        return array('html' => $html, 'javascript' => $script);
    }
}
 
// The class neeeds to be registered
\Workflow\Fieldtype::register('[IndividualNameA]', '\Workflow\Plugins\Fieldtypes\[IndividualNameA]');

Использование настраиваемых полей инвентаризации use custom Inventory Fields

Если вы используете настраиваемые поля в Задаче Inventory, такие как Счет, Коммерческое предложение, то значения этих полей будут очищены при выполнении любого другого Бизнес-Процесса и вы не сможете взаимодействовать с ними из Дизайнера Бизнес-Процессов, если версия вашего vTiger ниже 600.0825.

С этой версией вы сможете создавать файлы с именем “InventoryFields.inc.php” прямо в директории “extends”.
Эти файлы не будут переписаны во время обновления.

В этом файле вы можете настраивать создаваемые вами поля и сохранять их при выполнении Бизнес-Процессов.
Этот файл ОБЯЗАТЕЛЬНО ДОЛЖЕН иметь следующую структуру:
По той причине, что этот файл будет включен в каждое выполнение Бизнес-Процесса во всех модулях Inventory, вы должны вносить изменения осторожно.
Любая ошибка в этом файле сделает выполнение любого Бизнес-Процесса невозможным.

<?php
/**
 * You need to enter the following php structure
 *
 * return array(
 *    'tableCol' => array('inventoryField' => 'FieldNameWithoutProductIndex', 'label' => 'Label of this field'),
 * );
 */
// Example:
 
return array(
    'test' => array('inventoryField' => 'testCol', 'label' => 'Testvalue'),
);

tableCol Это имя колонки в таблице vtiger_inventoryproductrel. Не используется для чтения из БД, но подходит для использования как уникальное имя
FieldNameWithoutProductIndex Это код значения в ProductsArray. Вы используете это значение в функции “getAssociatedProducts”
Testvalue Является названием этого поля, которое будет показано в настройках Задачи

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