Welcome to MSDN Blogs Sign in | Join | Help

Doing Math in Microsoft CRM aka Calculated Fields

This is a question I get about once a week and got tired of typing up the same email over and over again. J Doing Math in Microsoft CRM using Jscript is mind numbingly easy. If you can do an Excel (Or VisiCalc) math equation, then you can do one in Microsoft CRM.

How you ask? Insert a Jscript on the field that you want the math done in. (So if you want Annual Income plus Alimony, this is how you could do it… And this is in case you can forget about the Anniversary date or month. J)

So you will have three fields:

1.   Annual Income – new_AnnualIncome

2.   Annual Alimony – new_AnnualAlimony

3.   Total Annual Income – new_totalannualincome

On the Total Annual Income, put a OnChange script that looks a little like this:

crmForm.all.new_totalannualincome.DataValue = crmForm.all.new_annualincome.DataValue + crmForm.all.new_annualalimony.DataValue;

Under normal circumstances CRM will not include disabled fields when saving forms even when the data has been changed.  We can, however, force CRM to include this field by using the ForceSubmit property as seen below:

 crmForm.all.new_totalannualincome.ForceSubmit = true;

I would disable the field. Then on the other two fields, paste this Jscript into their OnChange event:

new_totalannualincome_onchange0()

So the math you can do includes:

Addition

+

Subtraction

-

Division

/

Multiplication

*

Published Thursday, August 10, 2006 7:00 AM by Ben Vollmer

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Doing Math in Microsoft CRM aka Calculated Fields

what would the Jscript look like if you want to Calculated more than one Field ?
Friday, August 11, 2006 5:11 AM by Zulu

# re: Doing Math in Microsoft CRM aka Calculated Fields

Give me an example...
Friday, August 11, 2006 7:46 AM by Ben Vollmer

# http://ronaldlemmen.blogspot.com/2006/08/save-disabled-fields.html

Saturday, August 12, 2006 7:27 AM by TrackBack

# re: Doing Math in Microsoft CRM aka Calculated Fields

Cool, thanks man, that was an eye opener for someone that had no ideia of how to do it.

Wednesday, October 18, 2006 10:33 AM by Ivan

# Follow-up from Convergence 2007 Session

My apologies in not getting this up sooner. I flew home on the red-eye on Wednesday night, drove from

Friday, March 16, 2007 12:12 PM by East Region Microsoft CRM

# Follow-up from Convergence 2007 Session

My apologies in not getting this up sooner. I flew home on the red-eye on Wednesday night, drove from

Friday, March 16, 2007 1:22 PM by East Region Microsoft CRM

# re: Doing Math in Microsoft CRM aka Calculated Fields

Hey i am curious about a calculated field like the estimated opportunity revenue. where the field is calculated by x - sum(child:x). is there an easy way to do that on the form?

Thursday, April 12, 2007 10:36 AM by David

# re: Doing Math in Microsoft CRM aka Calculated Fields

Easy answer? No. :-) With some work, yes... But easily... No...

Thursday, April 12, 2007 4:59 PM by Ben Vollmer

# re: Doing Math in Microsoft CRM aka Calculated Fields

How do i set up a similar calculated totals in a structure similar to contracts and their contract lines? When you add a figure in contract lines the total figure in the contract gets updated

Wednesday, June 06, 2007 10:01 AM by Maina

# re: Doing Math in Microsoft CRM aka Calculated Fields

Maina,

That would require a little custom work... You should do a post call out with an application calling CRM's web service to make the update. :-)

Thanks!

Ben

Sunday, June 10, 2007 8:55 PM by Ben Vollmer

# re: Doing Math in Microsoft CRM aka Calculated Fields

Hi to all! I'm going mad,

my math customization problem is this:

When you go to

Sales -> Offers and than open an existing Offer the toolbar have a button Recalculate.

This calcolous find actual(at the moment of the launch) prices of all products and sum for a new total (if the prices are changed from the previous launch), this is very interesting because manage the list of products associated to the offer, I need this too.

Well, I have to do a simple thing (but I'm walking on the darkness!) I've added a picklist (simple!) with some voice of type "add 10% to the total amount of offer" or "apply Christmas discount to tech products" ecc

I've added a new button "MyRecalc" to the toolbar (simple!)

BUT I'don't have idea to how apply my personal calcolous related to the picklist choice.

Wich is the way to do that? There's examples, exist somewhere the source code of the original "Recalculate" method?

Heeeeeelp :)

Panez

PS if the solution exist I hope it's doesn't use Webservices, I build a custom web service that work if called in a web application inside an Iframe but when I call web service methods inside javascript I've got empty response (I don't know if the web service really respond to my call).

PPS Sorry for my English

Friday, August 03, 2007 6:18 AM by Panez

# re: Doing Math in Microsoft CRM aka Calculated Fields

Is it possible to do dependant math? i.e.: form1 + form2 only if form3 = x

The usage I am looking for is a total of grant funds. Funds from form1, plus funds from form2 but only if the funds in form2 are eligible as specified in a yes or no menu on form3.

Thanks in advance for the help!

Monday, August 20, 2007 11:10 AM by Mike Menser

# re: Doing Math in Microsoft CRM aka Calculated Fields

I apologize. I think that my usage gives the wrong impression. This is all on the same form, but in 3 different fields.

Monday, August 20, 2007 11:11 AM by Mike Menser

# re: Doing Math in Microsoft CRM aka Calculated Fields

I keep getting an error... I do not get the output from the equation in my ending field, and when I try to enter text into the field I get "This control only accepts strings as null or input"

Monday, August 20, 2007 12:16 PM by mmenser

# re: Doing Math in Microsoft CRM aka Calculated Fields

Could you share your formula?

Monday, August 20, 2007 3:27 PM by Ben Vollmer

# re: Doing Math in Microsoft CRM aka Calculated Fields

Thanks for all the wonderful tips Ben.. you are my CRM hero! I did get the last thing figured out and the code works now. I still never figured out doing dependent math, as stated in my first post. I do have a NEW question... I was wondering if you can do math with date fields. Here is the usage:

Say there is a field that says "Date Letter Was Mailed", and then there is a second field for "Followup Date". Well, my follow up date should be 30 days after the letter was sent. So if I fill in the "Date Letter Was Mailed" field, I would like the Followup Date to populate automatically with the date that would be 30 days from the date the letter was sent. Any ideas??

Wednesday, September 19, 2007 3:55 PM by mmenser

# re: Doing Math in Microsoft CRM aka Calculated Fields

M-

Lookup in the JavaScript Bible doing math on Date Fields. It takes a little more work, but is pretty easy. I don't have it in front of me, but it works VERY well. :-)

Thanks!

Ben

Monday, September 24, 2007 3:56 PM by Ben Vollmer

# re: Doing Math in Microsoft CRM aka Calculated Fields

Ben-

Thanks so much for the info - it's much appreciated.  Would you happen to know why I might be getting 'object exptected' errors whenever I update either factor variable?  I've tried your method and the fireonchange() function and I end up with the same error.  If I manually change the sum field it then calls the onchange function and works properly...

Thanks!!

Wednesday, October 03, 2007 2:01 AM by Dave Secker

# re: Doing Math in Microsoft CRM aka Calculated Fields

I used an addition function on quotes, orders, and invoices that worked in 3.0 but after the upgrade, something is working quite right.

I cannot convert an order to an invoice whenever I have data in my fields that are calculated.  I can convert a quote to an order but my total doesn't show on the order after the conversion.

I keep wondering what changed?

Thursday, March 13, 2008 9:34 AM by Stacy

# re: Doing Math in Microsoft CRM aka Calculated Fields

I keep getting a "object is null" error... I followed your steps exacly. Could someone help me figure this out?  All I am trying to do is add two money fields...

Friday, April 04, 2008 10:30 AM by Maria

# re: Doing Math in Microsoft CRM aka Calculated Fields

I have a custom entity that I created with a "Amount Received" field.  This Entity have a N:1 relationship with an account.  I am trying to get help on the web service code it would require to have a total field on the account that will look at & sum all the related "Amount Received" fields for the child entity.  Could you give me some direction?

Thursday, May 01, 2008 4:31 PM by Travis Engler

# CRM Live: custom calculation on Quote Details

In CRM Live (which doesn't support plugin and custom workflow actions), how do we calculate a custom sub-total of Quote Products based on the category / Subject of the product. For example, if a Quote has multiple Quote Product, each Quote Product can be categorized by the subject of the Product (like Materrial + Labour), how do we calculate the sub-total of all the materials and sub-total of all the Labour?

I added 2 new attributes to Quote entity for holding the sub-total and I can to an extent achieve the goal by using 2 different workflows on the Quote Product entity (one each for record created and record deleted triggers), how ever I cam not able to do the calculations if someone updates an existing Quote Product record's price or quantity. this would have been easy with plugins, but CRM Live doesn't support plug-ins.

Any input on this is truely appreciated. Thanks

Wednesday, May 21, 2008 11:51 AM by Kona Sirohi

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker