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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Dynamics

From novice to tech pro — start learning today.