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, …)

Additional functions

There are existing some special functions you could use to do vtiger related special tasks.
Also you could create your own functions Read this and also read this

custom function Examples

This example is only written to demonstrate the functions and could be done better.

  $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;
}

These function could be used inside the delay task to wait one day, or the amount of days in the Purchase Order Field of an invoice.

Here you could see one limitation of my implementation:

If you want use mathematical operations, you have to use parentheses to become the correct result, because the system ignore basic mathematical rules.

Other examples

Wait until same day next month

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

Wait 5 days

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