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)

set SPECIFIC field in a SPECIFIC section to read only using javascript

(0) ShareShare
ReportReport
Posted on by

I one field in two locations on the form.

I know if I pull up the properties of one field, I can set it to read only WITHOUT the change effecting the same field in the other section.....

I need to do this with code, but I'm not quite sure how to grab the section/field rather than just the field.

I know I can do  Xrm.Page.getAttribute("field name").getValue();   to acquire the field value, BUT I want to make sure I get the correct field in the section I specify.

Please help thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    TonyN Profile Picture
    695 on at

    Something like this should work. Just pass the name of the section that the field is in and the name of the field. I used ctrl.getName().search(field) because CRM appends a number to the end of duplicate fields.

    i.e. If you add new_field to the form it is named new_field. If you add a second new_field it is named new_field1.

    The only issue is if your field name is a substring of another field name. i.e. account and new_account

    //set specified field read only in specified section
    function setReadOnly(section, field) {
        var ctrlName = Xrm.Page.ui.controls.get();
        for (var i in ctrlName) {
            var ctrl = ctrlName[i];
            
            if (ctrl.getName().search(field) != -1) {
                alert(ctrl.getParent().getName());
                var ctrlSection = ctrl.getParent().getName();
                if (ctrlSection == section) {
                    ctrl.setDisabled(true);
                }
            }
        }
    }


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