• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 907
  • Last Modified:

CRM 2011 JavaScript "Weighted Value" Any help is really appreciated.

Good day,

I've been stuck on this for days now and I can't make any progress.

I'm trying to create a OnChange event to trigger when the OptionSet is changed to calculate a new weighted value i.e.-

value * probability /100 = new read only field

value =                        Currency                     "estimatedamount"
probability=                OptionSet(25/50/75)   "leadqualitycode"
new read only field=   Currency                    "pi_weightedestvalue"

I've created a Web Resource with the following Java...however I'm further away now than I was three days ago.

function UpdateField() {

est = Xrm.Page.GetAttribute("estimatedamount").getValue();
prob = Xrm.Page.GetAttribute("leadqualitycode").getValue();

if(est.getValue() != null)


Xrm.Page.GetAttribute(pi_weightedestvalue).setValue( est * prob * 0.01)



Any help is hugely appreciated.


1 Solution
Chinmay PatelEnterprise ArchitectCommented:
What happens when you try to execute this? Also how familiar you are with JavaScript and XRM Page object model?
Feridun KadirPrincipal ConsultantCommented:
OK, there are several things wrong with your script. Try the following:

function UpdateField() {

    if (Xrm.Page.getAttribute("estimatedamount").getValue() != null) {

        est = Xrm.Page.getAttribute("estimatedamount").getValue();
        prob = parseInt(Xrm.Page.getAttribute("leadqualitycode").getSelectedOption().text);

        Xrm.Page.getAttribute("pi_weightedestvalue").setValue(parseFloat(est * prob * 0.01));

Open in new window

Some points:
- JScript is case sensitive. So you must always use getAttribute
- To get the text in an option set you must use .getSelectedOption().text and then convert it to a number
- to set the value for a currency (or numeric) field use parseFloat to ensure that the value is converted to a floating point number
Performance_ImprovementsAuthor Commented:
Thank you Feridun,

You are my hero, your solution worked perfectly first time. I now get a weighted value that saves correctly and without errors.  

Kindest regards,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now