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
    Pawar Pravin 5,231 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
    Alex Fun Wei Jie 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
    Alex Fun Wei Jie 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
    naZir 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
    Alex Fun Wei Jie 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans