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:custom-functions [2014/06/12 19:26]
swarnat [Additional functions]
— (current)
Line 1: Line 1:
-====== Custom functions ====== 
  
-<WRAP important round> 
-==== 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! 
-</​WRAP>​ 
- 
-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,​ ...) 
-==== Arrays ==== 
- 
-From version 1.7 custom functions could be handle arrays and make use of the foreach function. This could be used espacelly for the environment variables. 
- 
-==== Environment Variables ==== 
- 
-From version 1.7 every execution of a workflow have it's own environment variables, which will be available from all custom expression fields. 
-They could be read and write over the variable $env.... 
- 
-==== Additional functions ==== 
- 
-I have added some special PHP functions you could use to do special tasks. 
-Also you could create your own functions. [[en:​extensions:​workflowdesigner:​customization|Read here]] 
- 
-**<fc #​777777>​wf_documentlink($crmid)</​fc>​** 
- 
-This function will return the complete download link for a Record inside Documents and could for example be used in eMails. 
- 
-  * **$crmid** - mixed (integer/​string) The CRM-ID of the Document Record (current Record is $crmid) 
- 
-example: 
-<code php> 
-return "<a href='"​..wf_documentlink($crmid)."'>​Download File</​a>";​ 
-</​code>​ 
- 
-**<fc #​777777>​wf_get_entity($crmid)</​fc>​** 
- 
-Returns an array with all values from the record you specify with $crmid. 
- 
-  * **$crmid** - mixed (integer/​string) Set the CRM-ID to load 
- 
-example: 
-<code php> 
-$entity = wf_get_entity($assigned_user_id);​ 
-return $entity["​email1"​];​ 
-</​code>​ 
-This will return the primary email address of the assigned to User. (I know this could be done easier, but you could get also the email from the reports_to User within the assigned_to User in this way.) 
- 
-**<fc #​777777>​wf_date($db_date,​ $interval, $format)</​fc>​** 
- 
-This function makes date calculation easier. If you only wants to format a given date, please use the default php date function. 
- 
-  * **$db_date** - string\\ Date to format/​change in format YYYY-MM-DD 
-  * **$interval** - string\\ This sets the interval, which would be applied to the $db_date.\\ Possible are all values from http://​www.php.net/​manual/​de/​datetime.formats.relative.php 
-  * **$format** - string\\ The format of the return date. (Possible placeholder:​ http://​php.net/​manual/​en/​function.date.php) 
- 
-example: 
-<code php> 
-return wf_date("​2001-12-31",​ "+1 day", "​d.m.Y"​);​ # returns 01.01.2002 
-</​code>​ 
-\\ 
-**<fc #​777777>​wf_dbquery($sql)</​fc>​** 
- 
-Returns an array with all columns from first row of the sql query. 
- 
-  * **$sql** - string Which SQL Query should be executed 
- 
-example: 
-<code php> 
-$record = wf_dbquery("​SELECT setype, crmid FROM vtiger_crmentity ORDER BY createdtime DESC LIMIT 1"); ; 
-return $record["​crmid"​];​ 
-</​code>​ 
-Get the CRMID of the latest record in your vtiger system. 
- 
-**<fc #​777777>​wf_dbSelectAll($sql)</​fc>​** 
- 
-returns an array with all result rows with all columns, this query will return 
- 
-  * **$sql** - string Which SQL Query should be executed 
- 
-example: 
-<code php> 
-$record = wf_dbSelectAll("​SELECT setype, crmid FROM vtiger_crmentity ORDER BY createdtime DESC LIMIT 10"); ; 
-/* 
-$record will be  
-array( ​ 
-  array( "​setype"​ => "​Leads",​ "​crmid"​ => 1),  
-  array( "​setype"​ => "​Contacts",​ "​crmid"​ => 2 )  
- ) 
-*/ 
-</​code>​ 
-Get the CRMID of the latest record in your vtiger system. 
-==== custom function Examples ==== 
- 
-This example is only written to demonstrate the functions and could be done better. 
-<code php> 
-$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; 
-} 
-</​code>​ 
- 
-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 
-<code php> 
-return date("​Y-m-d",​ strtotime("​+1 month"​));​ 
-</​code>​ 
- 
-Wait 5 days 
-<code php> 
-$days = 5; 
-$date = strtotime($datefield);​ 
-return date("​Y-m-d",​ $date + (86400 * $days)) 
-</​code>​