Tuesday, 20 May 2014

CRM 2013 Calculate Multiple Fields Using Business Rules

Business Rules in CRM 2013 is new feature and can help a non-developer background user to do some simple things, such as set Requirement fields, set Visibility, Set Enable or Disable, and Simple Calculation.

Sometimes, I am as developer also feel tempted to try this when I feel worth it to not use Javascript for every conditions I face.

But, for complex calculation or formula, Business Rules cannot support it by default since the formula can afford two fields as formula.

Now, I have this requirement :

Business Rules Calculate Multiple Example

To count the Total Food Claim, I have to calculate Breakfast, Lunch, and Dinner Expense, and also Snack Expense.

Means that Total Food Claim = Sum of (Breakfast Expense + Lunch Expense + Dinner Expense + Snack Expense).

Business Rules in CRM 2013 basically only can afford for simple calculation, 2 fields only as formula set field value.
 
image

So, it can be tricky, but it is possible!

Because, in the Action, you can have more than one action for each Business Rules, the actually we can take this advantage and need some trick and effort to do it gradually, action by action.

To achieve this without JavaScript, but using Workflow or Business Rules, you have to set the value gradually, step by step, and using multiple business rules for each condition.

Here is the guide.

1. Create first Business Rules with Field1 is contain data, in my case : Breakfast Expense :
 
Business Rules Calculate Multiple Field 1
 
2. Do it until your first Business Rules will become this :

Put your formula of calculation in Action gradually for each field

clip_image002


3. Create a new Business Rules based on this Business Rules as Template, utilize the Save As Button, now in this time attach to the contradict Condition:

Business Rules Calculate Multiple Field 1 Contrast


Because Business is currently not supporting If Else Statement, and you want to calculate your fields, even though one of the field is not containing any data.

4. Repeat for your other fields, for Field2, Field3, etc. In my case : Lunch Expense, Dinner Expense, Snack Expense.

This is the key, do it gradually for each field in Action.

Business Rules Calculate Multiple Field 4


5. So finally, you will have 8 Business Rules, depends on your Total Fields, if you have 7 fields, then you might need 14 Business Rules.

Business Rules Calculate Multiple All


6. Don't forget to activate all of them and then test them:

Fill in the fields

Business Rules Calculate Multiple Field Result


Business Rules Calculate Multiple Field Result On Change


If no dinner (zero value or no data of dinner expense)

Business Rules Calculate Multiple Field Result No Dinner


Hope it helps!

4 comments:

  1. Why visitrs still use to read news papers when in this technological globe all is pesented on web?



    Here is my website :: visit your url

    ReplyDelete
    Replies
    1. your grandchildren may ask why you still read on web when we can transfer knowledge straight into brains

      Delete
  2. I found the post very useful as well as interesting. I am certainly happy with all the dazzling opinions you serve in a fantastic way.

    Free Nifty Future Tips

    ReplyDelete
  3. there is one problem in this, that total will not work correctly except you have one filed with no data out of the 4 field.
    if you have 2 fields without data (in case they are optional) total will not work.
    to solve this
    put one rule to initialize all the fields with data as zero.
    and more over if you want to cover if the user clear one field from the data, during entry.
    then put separate rule for each field to make it back to zero if there is no data.
    this will work better if you have so many fields as 30 to add....

    ReplyDelete

My Name is..