Solved

CRM 2011 - JScript Math Calculation (Weighted Probability)

Posted on 2011-03-21
6
1,468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:stacko111
ID: 35184386
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
ID: 35187848
I get the following error:

Field: Window

Event: onload

Error:Object Expected
0
 
LVL 7

Expert Comment

by:stacko111
ID: 35187928
Are all those field names correct? Also are they all int fields or are some picklists or something else?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Wizard_IT
ID: 35188007
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
ID: 35188097
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
ID: 35334765
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

724 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