Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Make a record Read Only dynamically

(0) ShareShare
ReportReport
Posted on by 850

Hi I am trying to make a record read only in some specific condition.

I am able to make all fields read only but unable to do the same for grid Views in that form

Here is my code

function makingAllFieldreadOnly() {
debugger;
var statusValue = Xrm.Page.getAttribute("statuscode").getValue();
if (statusValue == 4) {
var controls = Xrm.Page.ui.controls.get();
for (var i in controls) {
var control = controls[i];
if (i == 10 || i == 11 || i == 12 || i == 21 || i == 22 || i == 26) {//To avoid GridView

}
else {
try {
if (control) {
control.setDisabled(true);
}
}
catch (e) {
alert(e.message + "");
}
}
}
}
else {
var controls = Xrm.Page.ui.controls.get();
for (var i in controls) {
var control = controls[i];
if (i == 10 || i == 11 || i == 12 || i == 21 || i == 22 || i == 26) {//To avoid GridView

}
else {
try {
if (control) {
control.setDisabled(false);
}
}
catch (e) {
alert(e.message + "");
}
}
}
}
}

Is there any supported way to amke grid view also read only..(Please Note:-I dont want to use RBW)

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Make a record Read Only dynamically

    Hi Nazir,

    You can use below code to make all fields as read only.

    function setFieldsDisabled(context) {

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

       if (name == "DisableFields") {

           var contact = context.getFormContext().data.entity;

           contact.attributes.forEach(function(field, i) {

               field.controls.get(0).setDisabled(true);

           });

       }

    }

    Also make sure that if you need to lock fields of header fields.

    If that is case please do use below code.

    Xrm.Page.getControl("header_logicalnameofattribute").setDisabled(true);

    Regards,

    Pravin

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi,

    you also can refer to below post.

    community.dynamics.com/.../780226

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi Nazir,

    please refer to below post

    community.dynamics.com/.../know-how-editable-grid-disable-fields-conditionally-using-javascript-dynamics-crm-d365-d365-editablegrid-1

    you need to use context.

  • naZir Profile Picture
    850 on at
    RE: Make a record Read Only dynamically

    Yes  ..What would be the scenario for editable grid view. for normal i can do it by writing Enable Rule

  • Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi,

    are you referring to editable grid view?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans