Solved

CRM 2011 - JScript Math Calculation (Weighted Probability)

Posted on 2011-03-21
6
1,462 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS CRM 4 - link fileld 11 70
fullcallendar did not show 2 65
Common Front Ends using Dynamics CRM 3 121
Location of Dynamics AX Service accounts in SQL 3 30
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.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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