defualt probability field in opportunity form based on sales stage RRS feed

  • Question

  • Hi I am new to js and MS CRM, been on it for a whole 2 days now :) manning the crm at the office temporally. 

    I have two questions

    I want to set values for the probability field based on sales stages, mine are called prospect, qualify etc. I tried this with a workflow, but I would like it to run when the form loads and when stage changes. From my research the last couple of days it seems the best way is with JS. Can one of you CRM super gurus help me out? 

    Also I tested a trivial hello world on load and it just didn't run, checked that the library was enabled and save/published the form but no dialog box loaded. are they any other prerequisites besides libraries to get JS scripts to work? 


    Wednesday, September 25, 2013 11:23 AM

All replies

  • Hi

    you can try this

    function setProbability()


    var myOptionSet = Xrm.Page.data.entity.attributes.get("salesstage"); var optionSetValue = myOptionSet.getValue(); var optionSetText = myOptionSet.getText(); if(optionSetValue=1) { Xrm.Page.getAttribute("closeprobability").setValue('56'); } elseif(optionSetValue=2) { Xrm.Page.getAttribute("closeprobability").setValue('76'); }


    Wednesday, September 25, 2013 12:02 PM
  • Thank you will do
    Tuesday, October 15, 2013 3:27 PM
  • Hi,

    For the basic helloworld example:

    1. Create a webresource of type javascript.

    2. Include the following in javascript:

    function helloScript(){



    3. Save the web resource

    4. Publish the web resource

    5. Open the form of the properties:

    6. Click on form properties. Include the web resource as the library.

    7. choose on load event. and add function helloScript.

    7. save and publish the form.



    • Proposed as answer by RameshwariSah Tuesday, October 15, 2013 5:51 PM
    Tuesday, October 15, 2013 5:49 PM