Ok lets start:
1) First create some fields. For this demo I’ll use: val1, val2 and result
2) The calculation will be a simple multiplication. I’ll multiply val1 and val2 and output the result in the result field.
1: function calculate()
3: var val1 = Xrm.Page.entity.attributes.get['new_val1'].getValue();
4: var val2 = Xrm.Page.entity.attributes.get['new_val2'].getValue();
9: var result = val1 * val2;
Mind the new Xrm page model functions that I’m using. More information can be found on MSDN.
A little more information on the JScript. First I grab the data from both fields, check if they are not null and then do the actual calculation. Finally I set the result for the “calculated field”.
5) Add a new Web Resource. Here you can give a name, description etc. For the “type”, select Script (JScript). Finally click on the button “Text Editor” and add the code we’ve created above.
6) Once the Web Resource is created and published we can use it in our Account form where the custom fields are located.
7) Customize the form and select “Form Properties”. We first need to make the Web Resource available in this specific form.
8 ) Under the Events tab, add the Web Resource that we just created.
9) All that’s left to do is to configure the onChange events for the two fields and we’re done. Doubleclick on the field val1 and val2, go to the Events tab and configure the onChange event. The final result for each field should look like this:
10) Publish the form and you’re ready for testing.