JavaScript–Calculate two fields

A friend contacted me the other day to help with a JavaScript issue.  He needed to calculate a couple of fields and found some code on Internet but wasn’t able to get it to work.  He found the code at

http://community.dynamics.com/crm/b/mshelp/archive/2011/03/14/creating-a-calculated-field-in-dynamics-crm2011.aspx

I took a look at the code and made some corrections.  For those of you that run into the same issue, I thought I would share the corrected code with you. 

function calculate ()

{
var val1 = Xrm.Page.getAttribute(‘new_val1’).getValue();
var val2 = Xrm.Page.getAttribute(‘new_val2’).getValue();

if(val1==null)return;
if(val2==null)return;

var result = val1 + val2;
Xrm.Page.getAttribute(‘new_totalvalue’).setValue(result);

}

Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s