Dynamic Required Fields – Using JScript for CRM 3.0

During a customer, sales or service lifecycle, requirements for data entry can change as a customer goes from being a prospect to a customer, from a cold opportunity to a hot opportunity, from a inquiry case to a system down case.


Using Jscript and a few minutes, here is a sample script that will allow you to have the fields required on a form change depending on where they are in their rating.


So a Cold Opportunity has NO required fields

A Warm Opportunity has the required fields of Estimated Close Date and Price List

A Hot Opportunity has required fields of the above PLUS Probability and Estimated Revenue.


Again, this is for DEMO Use. It has been tested and is for use only with our demo data. If you decide to use this on your own system, you do so at your own risk.


So this script needs to be attached to the Opportunity Rating Field. Refer to the IG on how to do this. The four fields we required should be attached to the script as dependencies.


Start Script Here ---


switch (parseInt(event.srcElement.DataValue, 10))



    /* Opportunity Rating Picklist */

    case 1:

        /* Hot */

        crmForm.SetFieldReqLevel("pricelevelid", 1);

        crmForm.SetFieldReqLevel("estimatedvalue", 1);

        crmForm.SetFieldReqLevel("estimatedclosedate", 1);

        crmForm.SetFieldReqLevel("closeprobability", 1);


    case 2:

        /* Warm */

        crmForm.SetFieldReqLevel("pricelevelid", 1);

        crmForm.SetFieldReqLevel("estimatedvalue", 0);

        crmForm.SetFieldReqLevel("estimatedclosedate", 1);

        crmForm.SetFieldReqLevel("closeprobability", 0);


    case 3:

    /* Cold */

       crmForm.SetFieldReqLevel("pricelevelid", 0);

       crmForm.SetFieldReqLevel("estimatedvalue", 0);

       crmForm.SetFieldReqLevel("estimatedclosedate", 0);

       crmForm.SetFieldReqLevel("closeprobability", 0);



    /* All other values */


       crmForm.SetFieldReqLevel("name", 0);

       crmForm.SetFieldReqLevel("customerid", 0);




Comments (20)
  1. kmycek says:

    I have tried to find documentation on the CRM DOM and I do not see the "SetFieldReqLevel" form method shown anywhere. I’m sure there are other useful form methods hidden as well. Can you please post a link to these "missing" methods? Thanks. -Keith

  2. Ben Vollmer says:


    This script was a 1.2 script that a few changes where made for 3.0…. I will see if I can dig a few more out… 🙂



  3. Mike Strubel says:

    Ben thanks for the script.  I am by no means a programmer but just dangerous enough to try.  What I find in using a script like this is that it is fine as you move up (from cold to hot) but it does not change the fields back to business suggested or no req if the oppurtunity was hot then changed to cold.  Is this acurate?  How can I accomplish this?

  4. Ben Vollmer says:


    This script as it is written goes both ways. So if it starts at Hot and goes to Cold, the fields will reflect that as well…



  5. Mike Strubel says:

    I did find this out, my issue was that I was using a bit field and changing it to a pick list allowed me to go back and forth.  Thank you for your reponse.  One more question, how can you change the field to be business suggested instead of required?

  6. Ben Vollmer says:


    I think you can… Try putting a 2 there… I did it for a client for 1.2, but have not played with it in 3.0….



  7. Ben Vollmer says:


    Here it is from 3.0.3 of the sdk.

    {Field}.RequiredLevel   Get property.

    Determines the level of requirement for the field. Valid values are:

    0 = No constraint (normal)

    1 = Business recommended

    2 = Business required





    var oField = crmForm.all.SOME_FIELD_ID;

    switch (oField.RequiredLevel)



         alert("This field is not required or recommended");



         alert("This field is business recommended");



         alert("This field is required");



  8. Luis Gutierrez says:


    Im trying to chage the required level of a field and I dont find any script to change it. Ben, could you post the script to change it?

    Many thanks,

  9. Ben Vollmer says:


    The script to change the required level is above.


  10. Luis Gutierrez says:

    Im sorry, forgot say that y use CRM 3.0

  11. Ben Vollmer says:

    The script above is for 3.0…

  12. Luis Gutierrez says:

    It´s true. I had a mistake. When I read the commentaries, think that the function "SetFieldReqLevel" dont run in CRM 1.2 and because of it i ask you for the function in CRM 3.0

    Many Thanks

  13. Ron Wallegie says:

    // — set required

    var oField = crmForm.all.yourfieldname;

    oField.req = 2;

    // — change the label to be required

    var oFieldLabel = document.getElementById(oField.id + "_c");

    if (oFieldLabel == null) return;

    // — the following sets the correct class for the label

    if (oFieldLabel.className.indexOf("req") != -1) return;

    if (oFieldLabel.className.indexOf("rec") != -1)


    oFieldLabel.className = oFieldLabel.className.replace("rec", "req");




    oFieldLabel.className = oFieldLabel.className + (oFieldLabel.className ==

    "" ? "req" : " req");


  14. ibiz says:

    So I am trying to use the code to change the type of field from business recommended to business required for certain picklist choices and then back to business recommended.

    After fiddling with it for an hour or so in different versions I can’t get the business recommended fields to return to their original state – they only go to normal or required and won’t go back to recommended.

    Any suggestions?

  15. Daniela says:

    I had the some problem.

    Try this code:

    crmForm.all.your_field.setAttribute("req", 1);

    crmForm.all.your_field_c.className = "rec";

    Replace "your_field" with "accountnumber" and "your_field_c" with


  16. Jim Allen says:

    Does the script change when moving to CRM 4.0?

  17. DaveBerry says:

    CRM 4.0 supports the SetFieldReqLevel call.  It even changes the appearance of the field when toggled, without having to change the className manually.




    … will toggle "custom_somefield" between Required and No Constraint, each time updating the look of the field to match either the red *, or blue + without additional, fancy code.

  18. Katyc says:

    I am working with crm 4.0 but crmForm.SetFieldReqLevel("custom_somefield",0); but dont change the look the field.

    could you helpme

  19. Pete Moss says:


    The code above works great and is nearly what i’m trying to achieve but I need it to….

    If field1 = certain picklist values then make field2 a required field BUT only when trying to save+close the activity.

    Ive tried adding in a questions each time the activity is saved which works but if you save+complete then it simply closes the window

    if(crmForm.all.new_appointmentoutcome.DataValue==null && crmForm.all.new_appointmenttype.DataValue==(1))


    var sao=confirm("Do you know the Sales Outcome Yet?");

    if (sao==true)


    crmForm.all.new_appointmentoutcome.setAttribute("req", 2);

    crmForm.all.new_appointmentoutcome_c.className = "req";






    any ideas what i can try??


Comments are closed.

Skip to main content