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

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    are you referring to editable grid view?

  • naZir Profile Picture
    850 on at

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

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    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.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you also can refer to below post.

    community.dynamics.com/.../780226

  • Suggested answer
    Pawar Pravin Profile Picture
    5,237 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans