Solved

CRM 2011 - JScript Math Calculation (Weighted Probability)

Posted on 2011-03-21
6
1,445 Views
Last Modified: 2012-08-13
On CRM 2011 I have an Opportunites form (standard)

I have created 4 new fields
1) Estimate High (new_estimatehigh)
2) Estimate Low (new_estimatelow)
3) Probability (%) (new_probability)
4) Weighted Probability (new_weightedprob)

I Basically need the following calculation to be done =Probability%*(Est.High+Est.Low)/2

I then need the answer to appear in Weighted Percentage

I would like this done in JScript as the workflows are pretty useless unless anyone can suggest otherwise?
0
Comment
Question by:Wizard_IT
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:stacko111
Comment Utility
Try putting this code in the OnChange event of fields 1-3 and also on the OnLoad event of the form:

crmForm.all.new_weightedprob.DataValue = crmForm.all.new_probability.DataValue * (crmForm.all.new_estimatehigh.DataValue + crmForm.all.new_estimatelow.DataValue)/2;
0
 

Author Comment

by:Wizard_IT
Comment Utility
I get the following error:

Field: Window

Event: onload

Error:Object Expected
0
 
LVL 7

Expert Comment

by:stacko111
Comment Utility
Are all those field names correct? Also are they all int fields or are some picklists or something else?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Wizard_IT
Comment Utility
new_estimatelow/new_estimatehigh - Currency Precision
weightedprob - Decimal Number
closeprobability - Whole Number

I have double checked all of the names (probability is closeprobability which I renamed in the line of code)

The System Field (closeprobability) is the only field that when you make a change it doesn't throw an error. All the other fields just show an error (Error: Object Expected)

0
 
LVL 7

Accepted Solution

by:
stacko111 earned 250 total points
Comment Utility
I've just realised what the problem is - the fields are showing an error because other fields don't have a value in, therefore the calculation is invalid.

I don't know in what order the fields will be populated but this will always be an issue if one or more of the fields don't have a value.

I would remove the code from the OnChange Events and put it into the OnSave event of the form (keep it in the onLoad as well). The only problem with this is the users won't see the change when they make amendments to the fields, the calculation will be done every time the form is loaded and saved.

Unless they will always fill in one field last in the sequence i.e. Weighted Probability, I don't see a way around this. If they do then also keep the code in the OnChange event of the field they will populate last.
0
 
LVL 27

Assisted Solution

by:Chinmay Patel
Chinmay Patel earned 250 total points
Comment Utility
Hi Wizard_IT,

On the similar lines as stacko111 has suggested, you can keep the logic on change but if the return value is NaN in JS than you can either avoid updating the field or display invalid result or something similar in the textbox and do not allow the user to save the record until they fix the error.

Regards,
Chinmay.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now