This is an old revision of the document!


Custom functions

Important
This Page describe a feature, which require PHP development skills.
If you use this feature in a wrong way, you could crash the Workflow!

Lots of Workflow Tasks in the Designer could use custom functions.

You recognize the option to use this functions, if you have an green border around a textfield and a special icon () next to the textbox.

Almost all such fields have special hints about this function. (for example, what value you have to return)

These scripts are default PHP Scripts with limited functions. All whitelisted PHP functions have the same arguments, like the original one. Each custom function have to return a value with the “return”statement.

You could use the following PHP functions:

  • md5, rand, implode, substr, explode, microtime, date, time, sha1, hash, intval, floatval, floor, ceil, foreach
  • all functions, started with “str” (strpos, str_pad, str_replace, …)

Дополнительные функции

Существуют несколько специальных функций, которые вы можете использовать, чтобы заставить vTiger сгенерировать специальные связанные задачи.
Так же вы можете создать свои собственные функции.
Документация доступна здесь: https://support.stefanwarnat.de/custom-functions/

Примеры пользовательских функций

Эти примеры написаны только для демонстрации функций, если вы можете - напишите лучше.

  $var1 = "864"."0";
$var1 = $var1.(0 + intval($vtiger_purchaseorder)).intval($vtiger_purchaseorder);
$var2 = 1 + (2 * 5) - 8;
$var1 = substr($var1, 0, 5);
if($vtiger_purchaseorder == "1") {
   $add = intval($var1) * $var2;
   return time() + $add;
} else {
   $add = intval($var1) * intval($vtiger_purchaseorder);
   return time() + $add;
}

Эта функция может быть использована, чтобы задержать выполнение задания на день или несколько дней в поле заказа на покупку в счете.

Здесь вы можете видеть единственный недостаток данного решения:

Если вы захотите использовать математические операции, то должны будете воспользоваться круглыми скобками, чтобы получить корректный результат, поскольку система игнорирует основные математические правила.

Другие примеры

Подождать до того же числа следующего месяца

return date("Y-m-d", strtotime("+1 month"));

Подождать 5 дней

$days = 5;
$date = strtotime($datefield);
return date("Y-m-d", $date + (86400 * $days))
Enter your comment. Wiki syntax is allowed:
  ____    ____  ____    _  __   ____
 / __ \  / __/ / __ \  / |/ /  / __/
/ /_/ / / _/  / /_/ / /    /  _\ \  
\____/ /___/  \___\_\/_/|_/  /___/