Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

Posted on by 670

i want to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box ?

mandatory.JPG

*This post is locked for comments

  • Verified answer
    account payable Profile Picture
    account payable 670 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Dear all ,

    Thanks

    finally I got solution please find below javascript code

    function addOrderType(item) {

       debugger;

               if (item.value == "AMC" && item.checked == true) {

                   parent.window.Xrm.Page.getAttribute("new_amcperiodfrom").setRequiredLevel("required");

                   parent.window.Xrm.Page.getAttribute("new_amcperiodto").setRequiredLevel("required");

                   document.getElementById("so_ordertype_3").disabled = true;

                   document.getElementById("so_ordertype_4").disabled = true;

                   document.getElementById("so_ordertype_5").disabled = true;

                   document.getElementById("so_ordertype_6").disabled = true;

    }

    if (item.value == "AMC" && item.checked == false) {

                   parent.window.Xrm.Page.getAttribute("new_amcperiodfrom").setRequiredLevel("none");

                   parent.window.Xrm.Page.getAttribute("new_amcperiodto").setRequiredLevel("none");

                   document.getElementById("so_ordertype_3").disabled = false;

                   document.getElementById("so_ordertype_4").disabled = false;

                   document.getElementById("so_ordertype_5").disabled = false;

                   document.getElementById("so_ordertype_6").disabled = false;

    }

    }

    solution1.JPG

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi Sabih,

    Modified Aric's code , accessing from web resource to form using window.parent. 

    Just replace the field name and trigger in on change of checkbox which you want.

            function chkAMC_OnChange() {
                var isChecked = Xrm.Page.getAttribute("new_chkAMC").getValue();
                if (isChecked) {
                    window.parent.Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("required");
                    window.parent.Xrm.Page.getAttribute("new_toDate").setRequiredLevel("required");
                }
                else {
                    window.parent.Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("none");
                    window.parent.Xrm.Page.getAttribute("new_toDate").setRequiredLevel("none");
                }
            }


  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Take the help of the following code. Hope it helps:

    $(document).ready(function() {

    $("#chekcboxControlId").change(function() {
    if(this.checked) {
    window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("required");
    }
    else
    {
    window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("none");
    }
    });

    });

    If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

     

     
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi,

    then refer to the link, on that particular checkbox checked, trigger the JS

    function myFunction()

    {

      if(htmlcheckbox== true)

        window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("required");

    else

    window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("none");

    }

  • account payable Profile Picture
    account payable 670 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi Wei Jie Fun,

    yes all the checkbox are built using html

    HTMLPASSWEBRESOURCE.JPG

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi,

    for all the checkboxes, are they built using html code?

    if yes, follow below post

    butenko.pro/.../howto-htmljs-webresources

  • account payable Profile Picture
    account payable 670 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    checkbox of AMC using from option set so how to write javascript code

    srvcordrtype.JPG

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    You can do this using JavaScript or Business Rule.

    On the change event of the checkbox, set the Requirement Level of the two fields to required.

    Using JavaScript:

    function chkAMC_OnChange()

    {

      var isChecked = Xrm.Page.getAttribute("new_chkAMC").getValue();

      if (isChecked)

      {

         Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("required");

         Xrm.Page.getAttribute("new_toDate").setRequiredLevel("required");

      }

      else

      {

         Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("none");

         Xrm.Page.getAttribute("new_toDate").setRequiredLevel("none");

      }

    }

    JavaScript file should be created and uploaded to server as web resource.

    Add Web Resource to form, and add the onChange event to the checkbox control and enter the function name where required.

    Logic should be similar to above using Business Rules.

    Hope this helps.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi,

    you can use business rule to achieve this

    community.dynamics.com/.../using-business-rules-to-hide-fields-and-make-them-required-as-needed

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: how to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box in crm on premise ?

    Hi Sabih,

    You can use Business Rule  or JavaScript to make field mandatory no other field change.

    Thanks,

    Shahbaaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans