User Tools


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:update_workflows [2014/07/14 17:19]
joebordes [Update Workflows]
en:update_workflows [2020/12/04 16:37] (current)
joebordes [Aggregations]
Line 1: Line 1:
-====== Update ​Workflows ​======+====== Update ​Workflow Tasks ======
  
 TBD TBD
 +
 +===== Aggregations =====
 +
 +When you want to update a field from a workflow (even on a related module), you have the option to use a function expression. There are many options here, two of which are the '​aggregation'​ and '​aggregation_fields_operation'​ functions. The default output, once you select one of these is:
 +
 +<​code>​
 +aggregation(operation,​relatedmodules,​relatedFieldToAggregate,​conditions)
 +</​code>​
 +
 +or
 +
 +<​code>​
 +aggregation_fields_operation(operation,​RelatedModule,​relatedFieldsToAggregateWithOperation,​conditions)
 +</​code>​
 +
 +Use this small guide to get you going:
 +
 +  * For the '​operation'​ parameter, you have the following choices (I think they speak for themselves):​
 +    * sum
 +    * min
 +    * max
 +    * avg
 +    * count
 +    * std
 +    * variance
 +    * group_concat
 +
 +The related module is the module you want to aggregate from. This can be the same module as you're creating the workflow on. You would use this if you want to update a field on a related record by summing up (for instance) all the '​siblings'​ of the record you are editing. For instance, you could update a field in Accounts with the sum of all payments made to that account, whenever you edit or save one of those payments, without having to save the Account in question first.
 +
 +The related field(s) should be field names of the module you specified in the previous parameter. Again, this can be one the same module you're creating the workflow on.
 +
 +The conditions should be an array-like formatted string with 4 parameters (example: [relatedto2,​e,​$(relatedto2 : (LitigationMatter) matter_name),​or])
 +
 +The first parameter tells the workflow which field to look for on the '​sibling'​ records.
 +
 +The second is the operator. In the example, there is an '​e',​ which stands for '​equals'​.
 +
 +The third parameter tells you what the fields in the '​relatedto2'​ field on the sibling should match. In this case, a nested expression is used to get the name of the related LitigationMatter,​ so basically you want all '​siblings'​ that have the same name in that field
 +
 +The last parameter tells the workflow how to '​glue'​ conditions together if you have multiple (yes, you can have multiple condition arrays).
 +
 +<WRAP center round important 75%>
 +IMPORTANT NOTE: Do not use spaces in the condition array-string between the arguments.
 +</​WRAP>​
 +
  
 ===== Examples ===== ===== Examples =====
Line 12: Line 57:
  
 <​code>​concat('​Your answer is ',​cf_###​ + cf_###,'​ units to small'​)</​code>​ <​code>​concat('​Your answer is ',​cf_###​ + cf_###,'​ units to small'​)</​code>​
 +
 +??? Can you show us an example of an if-else formula?
 +
 +!!! Sure, he is one that sets a currency field depending on a country field
 +
 +<​code>​if cf_843 == '​Colombia'​ then '​USD'​ else if cf_843 == '​Madrid'​ then '​EURO'​ else if cf_843 == '​London'​ then '​GBP'​ else if cf_843 == 'Hong Kong' then '​HKD'​ else if cf_843 == '​Melbourne'​ then '​AUD'​ else ' ' end</​code>​
 +
 +Things to respect:
 +  * all on one line, no new lines for nice formatting, although it may work, it may not
 +  * simple quotes (') not double (")
 +  * the last else value has a space ('​[space here]'​),​ that is important, if you put an empty string (''​) it will not work
 +
 +??? In a workflow update task, we want to use a formula like the below, in order to update the value of a field:
 +
 +<​code>​if time_diffdays(cf_855,​get_date('​today'​)) > 60 then add_days(get_date('​today'​),​ 28) else '​01-01-1970'​ end</​code>​
 +
 +That is, if the date in cf_855 is more than 60 days in the future, then the formula result is (today + 28 days), otherwise the formula result is 1-1-1970.
 +
 +We have tried several different syntaxes but none of them are working. ​ Can you help?
 +
 +
 +!!! There are two issues here that are based on the same principle: we are very limited in the possibility of embedding operations. With that I mean that workflow update formulas do not accept having an expression inside an expression. So
 +
 +<WRAP center round alert 60%>
 +This is comment is not true anymore in coreBOS. We can now embed expressions inside expressions with no limitation. Althought the solution proposed here using intermediate fields is valid, you should be able to launch the original "​if"​ expression now.
 +</​WRAP>​
 +
 +<​code>​if time_diffdays(cf_855,​get_date('​today'​)) > 60 then...</​code>​
 +
 +is incorrect because the condition must be basic operations. Also,
 +
 +<​code>​...add_days(get_date('​today'​),​ 28)...</​code>​
 +
 +is wrong for the same reason.
 +
 +So the solution is to use intermediate field calculations. In other words, artificial custom fields that hold the calculated values we need and also knowing that some base functions like add_days or time_diff accept only one parameter and "//​know//"​ that the other is "​today"​.
 +
 +The next image should achieve what you are asking:
 +
 +{{ :​en:​corebos:​workflow:​calcwf.png?​700 |}}
 +
 +<WRAP center round important 70%>Note that this is NOT time based, it will not calculate automatically when "​today"​ is over 60 days, you will have to edit the record EVERY day to see the changes.
 +As of March 2015 you can use scheduled workflows for time based workflows.</​WRAP>​
 +
 +