Solved

CRM 2011 - JScript Math Calculation (Weighted Probability)

Posted on 2011-03-21
6
1,452 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

14 Experts available now in Live!

Get 1:1 Help Now