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
Solved

CRM 2011 - JScript Math Calculation (Weighted Probability)

Posted on 2011-03-21
6
1,456 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crm dynamics how to move a lead to client and back to lead 3 98
App Says Services Are Stopped When They Are Not 13 117
Javascript -- "RIGHT" function ? 3 148
Dynamics crm 2011 8 89
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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