web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript reference

(0) ShareShare
ReportReport
Posted on by 1,942

Hi all,

I am getting all the controls using the Xrm.Page.ui.controls.get() library. Next thing is to look for a particular field/section and disable all its controls.

How do we do this? When i use the Xrm.Page.ui.controls.get() library it was having an array of collection of 45 elements. How do i select a particular object?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    You can try similar to this:

    Xrm.Page.ui.controls.get("<field name>").setDisabled(false);

    Xrm.Page.getControl("<field name>").setVisible(false);

    Refer the following:

    http://www.resultondemand.nl/support/sdk/78b715dc-9d33-49cb-b563-b5fa6839c251.htm

  • Suggested answer
    M I Mostafa Profile Picture
    4,257 on at

    You can access an attribute by name this way:

    var nameAttribute = Xrm.Page.getAttribute("name");

    Access attribute by index:

    var firstAttribute = Xrm.Page.getAttribute(0);

    Get all attributes: var allAttributes = Xrm.Page.getAttribute();

    Get attribute value: var nameValue = Xrm.Page.getAttribute("name").getValue();

    Full details here:

    msdn.microsoft.com/.../gg334266.aspx

    And here:

    msdn.microsoft.com/.../jj602964.aspx

    Hope this helps! Please click on "Yes" if you found this response has helped you.

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at
  • Vighnesh Profile Picture
    1,942 on at

    Thank you all for your swift responses. What i was looking for is to understand how to point a particular object after having the control list?

    Also i was using the below code to disable the control for a particular section of fields and don't know where it is going wrong. Used the parameters in the form properties but still no luck.

    function sectiondisable (BILLING, true)

    {

       var ctrlName = Xrm.Page.ui.controls.get();

       for(var i in ctrlName) {

            var ctrl = ctrlName[i];

            var ctrlSection = ctrl.getParent().getName();

            if (ctrlSection == BILLING) {

                  ctrl.setDisabled(true);

           }

       }

    }

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    instead of getName() use getLabel()

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    This is a modified code of yours and this should work.

    I am not sure how you are going to call this function (onChange or OnLoad).

    You have to pass the section name, true/false

    function sectionDisable(sectionName, disable)
    {
        console.log("sectionDisable function invoked");
        Xrm.Page.ui.controls.forEach(function (control, index) {
            
            if ((control.getParent() != null) && (control.getParent().getName() == sectionName)) {
                console.log(control.getParent().getName());
                control.setDisabled(disable);
            }
        });
    }


  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Vighnesh,

    You can select a particular object in the library by using the index. See the code below.

    var controls = Xrm.Page.ui.controls.get();
    var length = controls.length;
    var firstObject = controls[0];
    var lastObject = controls[length -1];

    Hope this helps.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    In order to hide the section, write the Javascript function below.

    function sectiondisable() {
        var ctrlName = Xrm.Page.ui.controls.get();
        for (var i in ctrlName) {
            var ctrl = ctrlName[i];
            var section = ctrl.getParent();
            if (section != null) {
                var ctrlSection = ctrl.getParent().getName();
                if (ctrlSection == "BILLING") {
                    ctrl.setDisabled(true);
                }
            }
        }
    }

    Hope this is your requirement.

  • Suggested answer
    Shidin Haridas Profile Picture
    3,499 on at

    Hi Vighnesh,

    1. If you need to just disable a particular control, you can use any of the following:

    1. Xrm.Page.ui.controls.get("fieldSchemaName").setDisabled(true);

    2. Xrm.Page.getControl("fieldSchemaName").setDisabled(true);

    2. If you want to find a particular attribute/object after using Xrm.Page.ui.controls.get(), then you can need to loop through all controls till you get the control you require using the schema name as follows:

    var controls = Xrm.Page.ui.controls.get();
    for (var i in controls) {
    var control = controls[i];
    if (control.getName="fieldAttributeName") {
    control.setDisabled(false);
    }
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans